I am trying to unit test the following directive. How ever I'm not sure in this case how or even what to test.
The part I am testing is the link function to my knowledge I can only test the outcome of calling watch. In the case below is there anything that I can test?
I originally wanted to make sure modalInstance was called but im not sure this is possible.
The directive: angular.module('pb.roles.directives') .directive('pbRolesModal', ['$modal', 'pbRoles', function ($modal, pbRoles) {
return {
restrict: 'A',
link: function (scope, element, attrs) {
scope.$watch(attrs.pbRolesModal, function (entity) {
if (entity) {
element.click(function () {
var modalInstance = $modal.open({
templateUrl: '/app/roles/views/_peopleRoles.html',
controller: 'RolesController',
resolve: {
entityId: function () {
return entity.entityId;
},
enabledRoles: function () {
return entity.enabledRoles || 0;
}
}
});
});
}
});
}
};
}]);
My setup so far:
describe('pbRolesModal', function () {
beforeEach(module(function ($provide) {
$provide.constant('organizationService', function () { });
$provide.service('activeProfile', function () { });
}));
beforeEach(module('pb.roles'));
beforeEach(module('pb.roles.directives'));
beforeEach(module('ui.router'));
beforeEach(module('ui.bootstrap'));
var compile, scope, element, isolate;
var html = '<button data-pb-role-auth data-pb-granted-roles="campaign.personRoles" data-pb-keep="Admin,Manager" data-ng-disabled="!campaign" data-pb-roles-modal="campaign" data-ng-class="{ \'btn-sm\': isHeaderMin }" class="btn btn-default-alt"><span class="fa fa-users"></span></button>';
beforeEach(inject(function ($compile, $rootScope, $q, $injector) {
compile = $compile
scope = $rootScope.$new();
$httpBackend = $injector.get('$httpBackend');
$httpBackend.whenGET('/app/roles/views/_peopleRoles.html').respond(200, '');
element = compile(html)(scope);
//$httpBackend.flush();
scope.$digest();
}));
describe('$watch', function () {
it('', function () {
});
});
});
Aucun commentaire:
Enregistrer un commentaire