This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: always run jasmine's done callbacks for async tests in jasmine's…
… zone If we don't, we are leaking zones because Jasmine executes async tests from within the done callback, which means we never unwind the zone stack. This causes various specs to fail if other specs run before them and build up a zone stack. Closes #91
- Loading branch information
Showing
4 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict'; | ||
|
||
(function() { | ||
// patch jasmine's it and fit functions so that the `done` callback always resets the zone | ||
// to the jasmine zone, which should be the root zone. (angular/zone.js#91) | ||
|
||
var jasmineZone = window.zone; | ||
var originalIt = window.it; | ||
var originalFit = window.fit; | ||
|
||
window.it = function zoneResettingIt(description, specFn) { | ||
if (specFn.length) { | ||
originalIt(description, function zoneResettingSpecFn(originalDone) { | ||
specFn(function zoneResettingDone() { | ||
jasmineZone.run(originalDone); | ||
}); | ||
}); | ||
} else { | ||
originalIt(description, specFn); | ||
} | ||
}; | ||
|
||
window.fit = function zoneResettingFit(description, specFn) { | ||
if (specFn.length) { | ||
originalFit(description, function zoneResettingSpecFn(originalDone) { | ||
specFn(function zoneResettingDone() { | ||
jasmineZone.run(originalDone); | ||
}); | ||
}); | ||
} else { | ||
originalFit(description, specFn); | ||
} | ||
}; | ||
|
||
}(window)); | ||
|
||
// global beforeEach to check if we always start from the root zone | ||
beforeEach(function() { | ||
expect(window.zone.isRootZone()).toBe(true); | ||
}); |