Here is some Javascript that makes a call to jqLite's trigger
inside the link
function of an AngularJS directive.
angular.
module('myApp').
directive('myDirective',
function($timeout) {
return {
link: function(scope) {
scope.resetChosenElements = function() {
$timeout(function() {
$('[chosen]').trigger('chosen:updated');
}, 0);
}
scope.resetChosenElements();
}
};
}
);
How can I write a test that checks that trigger
is called when the directive is created without spying on $.trigger
? (I don't want to spy on $.trigger
because that catches all calls made to it, including those form other directives).
Is there a way to spy on the element
argument that can be passed to link
?
EDIT: My comment about spying on element
seems to be causing confusion. I was only implying that if the solution required adding element
to the arguments passed to link
then that would be fine. However currently I have no use for it otherwise, which is why it's excluded from the argument list.