I have a few directives and services with registered watchers. I would like to make sure that all watchers are removed when the destroy method is called. Is there anyway of making sure this is the case?
Asked
Active
Viewed 1,550 times
1 Answers
1
First, I believe you should create a spy on the destroy method, just to make sure it is called.
spyOn(YourService, 'destroy').and.callThrough();
expect(YourService.destroy).toHaveBeenCalled();
So this makes sure your destroy function has been called, now for the watchers part, you can use the code described in this StackOverflow answer (https://stackoverflow.com/a/18526757/2483389) or in this blog entry (https://medium.com/@kentcdodds/counting-angularjs-watchers-11c5134dc2ef).
These provide methods to count the current number of watchers you are using. You should expect it to be 0 after the destroy method was called.

Community
- 1
- 1

Gabriel Pires
- 376
- 5
- 9