Below is a directive I am trying to test. I know how I am going to test it but I am having a hard time finding out how to call the functions in the link section in order to start testing it(ie. scope.accountClick ).
I was sure I would be able to do it like :
it('should call selectProfile()', function () {
jasmine.createSpy('selectProfile');
scope().profileClick(account, property, profile);
expect(scope.selectProfile).toHaveBeenCalledWith(account, property, profile);
});
But it does not get called. Someone suggested I needed to use element.isolateScope().profileClick(account, property, profile);
but that does not work either
The directive I am testing looks like this:
angular.module('pb.webSites.directives')
.directive('pbGoogleAnalyticsManagementList', ['$window', '$document', function ($window, $document) {
return {
restrict: "E",
templateUrl: "app/webSites/directives/GoogleAnalyticsManagementList.html",
scope: {
googleAnalyticsProfile: '=pbGoogleAnalyticsProfile',
selectProfileFn: '&pbSelectProfile'
},
controller: 'GoogleAnalyticsManagementController',
link: function (scope, element, attrs) {
scope.accountClick = function (account) {
//bunch of code
scope.getProperties(account);
};
scope.propertyClick = function (account, property) {
//bunch of code
scope.getProfiles(account, property);
};
scope.profileClick = function (account, property, profile) {
//bunch of code
scope.selectProfile(account, property, profile);
};
}
};
}]);
Aucun commentaire:
Enregistrer un commentaire