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

Commit be1e6fd

Browse files
committed
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.
1 parent 77419cf commit be1e6fd

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/ngMock/angular-mocks.js

+1
Original file line numberDiff line numberDiff line change
@@ -2480,6 +2480,7 @@ if (window.jasmine || window.mocha) {
24802480

24812481
if (injector) {
24822482
injector.get('$rootElement').off();
2483+
injector.get('$rootScope').$destroy();
24832484
}
24842485

24852486
// clean up jquery's fragment cache

test/ngMock/angular-mocksSpec.js

+15
Original file line numberDiff line numberDiff line change
@@ -1650,6 +1650,21 @@ describe('ngMock', function() {
16501650
});
16511651

16521652

1653+
describe('$rootScope', function() {
1654+
var destroyed = false;
1655+
1656+
it('should destroy $rootScope after each test', inject(function($rootScope) {
1657+
$rootScope.$on('$destroy', function() {
1658+
destroyed = true;
1659+
});
1660+
}));
1661+
1662+
it('should have destroyed the $rootScope from the previous test', function() {
1663+
expect(destroyed).toBe(true);
1664+
});
1665+
});
1666+
1667+
16531668
describe('$rootScopeDecorator', function() {
16541669

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

0 commit comments

Comments
 (0)