FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(ngMock): don't clean up if currentSpec is null. by heathkit · Pull Request #16856 · angular/angular.js · GitHub

This repository was archived by the owner on Apr 12, 2024. It is now read-only.
/ angular.js Public archive

fix(ngMock): don't clean up if currentSpec is null. - #16856

Open
heathkit wants to merge 1 commit into
angular:v1.6.xfrom
heathkit:v1.6.x
Open

fix(ngMock): don't clean up if currentSpec is null.#16856
heathkit wants to merge 1 commit into
angular:v1.6.xfrom
heathkit:v1.6.x

Conversation

heathkit commented Mar 22, 2019
edited
Loading

Copy link
Copy Markdown

In unit tests that use Angular and AngularJS, sometimes an error being thrown during the test and cause this afterEach hook to run twice. If that happens, on the second run cleanup will throw an error, since at that point currentSpec is null. This causes the original error to be hidden by a "TypeError: Cannot read property '$injector' of null while testing" error.

This makes cleanup safe to call multiple times, working around the issue.

This fix is needed to resolve an internal issue affecting Angular unit tests. I discussed this with Igor, and he asked me to submit this as a PR. No release is necessary, we just need this in google3.

heathkit changed the title fix(ngMocks): Don't clean up if currentSpec is null. fix(ngMock): Don't clean up if currentSpec is null. Mar 22, 2019
heathkit force-pushed the v1.6.x branch 2 times, most recently from 91a91b6 to 79b8317 Compare March 22, 2019 04:15
heathkit changed the title fix(ngMock): Don't clean up if currentSpec is null. fix(ngMock): don't clean up if currentSpec is null. Mar 22, 2019

gkalpak commented Mar 22, 2019

Copy link
Copy Markdown
Member

I would feel better if we understood why this happens. Why is the afterEach() block run twice?

In unit tests that use Angular and AngularJS, sometimes an error being
thrown during the test and cause this afterEach hook to run twice. If
that happens, on the second run cleanup will throw an error, since at
that point currentSpec is null. This causes the original error to be
hidden by a "TypeError: Cannot read property '$injector' of null while
testing" error.

This makes cleanup safe to call multiple times, working around the
issue.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL