-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): do not invoke jasmine
done
callback multiple times with …
…`waitForAsync` Currently tests written using `waitForAsync` would be prone to Jasmine warnings or errors (depending on the version) for tests incorrectly invoking asynchronous jasmine `done` callbacks multiple times. This can happen because the async test zone logic schedules the `done` callback to be called using `setTimeout`, but this could be invoked multiple times, causing multiple `done` invocations to be scheduled. Most of the issues have been resolved with #45025, but it does not solve the case of multiple tasks finished and callbacks being scheduled. Technically, the current logic is built in way that _should_ result in `_finishCallbackIfDone` and eventually the `done` callback to be invoked at maximium once. This is unfortunately not the case in some rather advanced/unexpected scenarios (like our AngularJS upgrade tests) where the scenario is the following (and microtasks from before the actual `waitForAsync` spec are still completing -- which is valid): ``` 1. A test `beforeEach` schedules a microtask in the ProxyZone. 2. An actual empty `it` spec executes in the AsyncTestZone` (using e.g. `waitForAsync`). 3. The `onInvoke` invokes `_finishCallbackIfDone` because the spec runs synchronously. 4. We wait the scheduled timeout (see below) to account for unhandled promises. 5. The microtask from (1) finishes and `onHasTask` is invoked. --> We register a second `_finishCallbackIfDone` even though we have scheduled a timeout. --> we execute the `done` callback twice because the async zone spec state is "stable" ```
- Loading branch information
1 parent
7ea0c2a
commit 4e77c7f
Showing
2 changed files
with
67 additions
and
5 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