$rootScope reference has been destroyed by angular-mocks
See original GitHub issueTLDR;
Unit tests don’t run ngOnChanges
correctly if they are run after another test because the $rootScope
reference was destroy.
Details
In my unit tests I am using the $compile
service to create my component and check the resulting DOM. After each test angular-mocks destroys the $rootScope
service to clean up the test (introduced in angular/angular.js#13433). However, angular does not invoke the directiveControllerFactory
again so when future tests run $apply()
in the _flushOnChangesQueue() function, it is calling a noop. This is evidenced by the ngOnChanges() not be called again.
When debugging this issue, I can run two copies of the same exact test and the first instance would pass and the second would fail. I will try creating an example unit test to demonstrate.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:8 (2 by maintainers)
Top GitHub Comments
We’re running into the same problem. For now we’re working around it by doing
$rootScope.$destroy = () => angular.noop();
. Not the best solution but at least it saves us from writing specific test code to work around the issue.sorry was busy with non Angular things lately. Need take a look. Sry for delay @aciccarello