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

Commit

Permalink
fix(ngMock): don't clean up if currentSpec is null
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
heathkit committed Mar 22, 2019
1 parent 33b5c50 commit 6bbc865
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ngMock/angular-mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3000,6 +3000,9 @@ angular.mock.$RootScopeDecorator = ['$delegate', function($delegate) {
};

module.$$cleanup = function() {
if (!currentSpec) {
return;
}
var injector = currentSpec.$injector;

annotatedFunctions.forEach(function(fn) {
Expand Down

0 comments on commit 6bbc865

Please sign in to comment.