Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit e55829a

Browse files
andyroogergkalpak
authored andcommittedFeb 22, 2016
feat(ngMock): destroy $rootScope after each test
Previously $rootScope would be new for each test, but old $rootScopes would never be destroyed. Now that we are able to destroy the $rootScope, doing so provides an opportunity for code to clean up things like long-lived event handlers between tests. Closes #13433
1 parent 571e323 commit e55829a

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed
 

‎src/ngMock/angular-mocks.js

+1
Original file line numberDiff line numberDiff line change
@@ -2330,6 +2330,7 @@ if (window.jasmine || window.mocha) {
23302330
}
23312331
angular.element.cleanData(cleanUpNodes);
23322332

2333+
injector.get('$rootScope').$destroy();
23332334
}
23342335

23352336
// clean up jquery's fragment cache

‎test/ngMock/angular-mocksSpec.js

+19
Original file line numberDiff line numberDiff line change
@@ -1603,6 +1603,25 @@ describe('ngMock', function() {
16031603
});
16041604

16051605

1606+
describe('$rootScope', function() {
1607+
var destroyed = false;
1608+
var oldRootScope;
1609+
1610+
it('should destroy $rootScope after each test', inject(function($rootScope) {
1611+
$rootScope.$on('$destroy', function() {
1612+
destroyed = true;
1613+
});
1614+
oldRootScope = $rootScope;
1615+
}));
1616+
1617+
it('should have destroyed the $rootScope from the previous test', inject(function($rootScope) {
1618+
expect(destroyed).toBe(true);
1619+
expect($rootScope).not.toBe(oldRootScope);
1620+
expect(oldRootScope.$$destroyed).toBe(true);
1621+
}));
1622+
});
1623+
1624+
16061625
describe('$rootScopeDecorator', function() {
16071626

16081627
describe('$countChildScopes', function() {

0 commit comments

Comments
 (0)
This repository has been archived.