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

ngMock breaks during clean-up with mocked $rootScope #14106

Closed
gkalpak opened this issue Feb 22, 2016 · 2 comments
Closed

ngMock breaks during clean-up with mocked $rootScope #14106

gkalpak opened this issue Feb 22, 2016 · 2 comments

Comments

@gkalpak
Copy link
Member

gkalpak commented Feb 22, 2016

#13433 introduced $rootScope clean-up after each test. The implementation assumes that $rootScope will always have a $destroy() method, which might not be true for a mocked/decorated $rootScope, resulting in an error.

Also discussed in #13985 (comment).

@Narretz
Copy link
Contributor

Narretz commented Feb 22, 2016

I think if you are mocking (essential) services then you need to provide their API surface. I would go as far as recommending against mocking things such as $injector, $rootScope etc.

gkalpak added a commit to gkalpak/angular.js that referenced this issue 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 angular#14106
@Narretz
Copy link
Contributor

Narretz commented Feb 22, 2016

Ok, I see how this can be confusing if you inject this in a service but you don't actually use any of the functions of the rootScope. So I'm okay with fixing this.

gkalpak added a commit that referenced this issue 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 issue 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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants