How to unit testing an $destroy event of a Directive in angularjs?
I have the code in my directive:
scope.$on(\'$destroy\', function () {
//clean som
Angular's isolateScope
is preferable to using jQuery. You've probably compiled the element in a beforeEach above your test like this:
myEl = 'MY EL';
scope = $rootScope.$new();
directiveElement = $compile(myEl)(scope);
scope.$digest();
Now in your test you can access the isolateScope
and call $destroy
:
var isolated = directiveElement.isolateScope();
isolated.$destroy();