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

Conversation

gkalpak
Copy link
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
@@ -2612,7 +2612,8 @@ if (window.jasmine || window.mocha) {
}
angular.element.cleanData(cleanUpNodes);

injector.get('$rootScope').$destroy();
var $rootScope = injector.get('$rootScope');
if ($rootScope.$destroy) $rootScope.$destroy();
Copy link
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
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
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
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