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

feat(ngMock): destroy $rootScope after each test #13433

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ngMock/angular-mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2480,6 +2480,7 @@ if (window.jasmine || window.mocha) {

if (injector) {
injector.get('$rootElement').off();
injector.get('$rootScope').$destroy();
}

// clean up jquery's fragment cache
Expand Down
15 changes: 15 additions & 0 deletions test/ngMock/angular-mocksSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1650,6 +1650,21 @@ describe('ngMock', function() {
});


describe('$rootScope', function() {
var destroyed = false;

it('should destroy $rootScope after each test', inject(function($rootScope) {
$rootScope.$on('$destroy', function() {
destroyed = true;
});
}));

it('should have destroyed the $rootScope from the previous test', function() {
expect(destroyed).toBe(true);
});
});


describe('$rootScopeDecorator', function() {

describe('$countChildScopes', function() {
Expand Down