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
Here is what I do:
var destroyed = spyOn(scope, '$destroy').and.callThrough();
scope.$destroy();
expect(destroyed).toHaveBeenCalled();
unlike other answers I don't have to create flag variables that only make sense for testing, also, it makes more sense to me to use Jasmine spyOn and callThrough to check if the function $destry is being successfully called.