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

fix(ngMock): don't break if $rootScope.$destroy() is not a function#14107

Closed
gkalpak wants to merge 2 commits into
angular:masterfrom
gkalpak:fix-ngMock-support-cleanup-for-mocked-rootScope
Closed

fix(ngMock): don't break if $rootScope.$destroy() is not a function#14107
gkalpak wants to merge 2 commits into
angular:masterfrom
gkalpak:fix-ngMock-support-cleanup-for-mocked-rootScope

Conversation

@gkalpak
Copy link
Copy Markdown
Member

@gkalpak gkalpak commented Feb 22, 2016

Previously, angular-mocks was calling $rootScope.$destroy() after each test as part of it's cleaning up, assuming that it was always available. This could break if $rootScope was mocked and the mocked version didn't provide the $destroy() method.
This commit prevents the error by first checking that $rootScope.$destroy is present.

Fixes #14106

Previously, `angular-mocks` was calling `$rootScope.$destroy()` after each test as part of it's
cleaning up, assuming that it was always available. This could break if `$rootScope` was mocked
and the mocked version didn't provide the `$destroy()` method.
This commit prevents the error by first checking that `$rootScope.$destroy` is present.

Fixes angular#14106
Comment thread src/ngMock/angular-mocks.js Outdated

injector.get('$rootScope').$destroy();
var $rootScope = injector.get('$rootScope');
if ($rootScope.$destroy) $rootScope.$destroy();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a comment about this being possibly undefined due to mocking?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Narretz
Copy link
Copy Markdown
Contributor

Narretz commented Feb 23, 2016

LGTM

@gkalpak gkalpak closed this in 871bebf Feb 23, 2016
gkalpak added a commit that referenced this pull request Feb 23, 2016
Previously, `angular-mocks` was calling `$rootScope.$destroy()` after each test as part of it's
cleaning up, assuming that it was always available. This could break if `$rootScope` was mocked
and the mocked version didn't provide the `$destroy()` method.
This commit prevents the error by first checking that `$rootScope.$destroy` is present.

Fixes #14106

Closes #14107
gkalpak added a commit that referenced this pull request Feb 23, 2016
Previously, `angular-mocks` was calling `$rootScope.$destroy()` after each test as part of it's
cleaning up, assuming that it was always available. This could break if `$rootScope` was mocked
and the mocked version didn't provide the `$destroy()` method.
This commit prevents the error by first checking that `$rootScope.$destroy` is present.

Fixes #14106

Closes #14107
@gkalpak
Copy link
Copy Markdown
Member Author

gkalpak commented Feb 23, 2016

Backported to v1.5.x (50ed871) and v1.4.x (24a7f28).

@gkalpak gkalpak deleted the fix-ngMock-support-cleanup-for-mocked-rootScope branch February 24, 2016 08:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants