mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
test(core): ensure async tests are awaited properly (#54801)
The assertion in `packages/core/test/acceptance/after_render_hook_spec.ts:165` was prone to flakes,
where Jasmine could frequently report an error:
```
Error: 'expect' was used when there was no current spec, this could be because an asynchronous test timed out
at Env.expect (node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1945:15)
at expect (node_modules/jasmine-core/lib/jasmine-core/jasmine.js:8267:18)
at file:///packages/core/test/acceptance/after_render_hook_spec.ts:165:12
```
This happens because `wrapTestFn` checks for an exact type of `Promise`, which may have been patched by zone.js
such that the `instanceof` condition is dependent on whether zone.js has patched the `Promise` constructor.
PR Close #54801
This commit is contained in:
parent
484ae23bbf
commit
0bcaa0ebee
1 changed files with 3 additions and 10 deletions
|
|
@ -76,16 +76,9 @@ function wrapTestFn<T extends Function>(
|
|||
html: string,
|
||||
blockFn: T,
|
||||
): T {
|
||||
return function (done: DoneFn) {
|
||||
if (typeof blockFn === 'function') {
|
||||
elementGetter().innerHTML = html;
|
||||
const blockReturn = blockFn();
|
||||
if (blockReturn instanceof Promise) {
|
||||
blockReturn.then(done, done.fail);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
}
|
||||
return function () {
|
||||
elementGetter().innerHTML = html;
|
||||
return blockFn();
|
||||
} as any;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue