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:
JoostK 2024-03-10 22:13:04 +01:00 committed by Andrew Scott
parent 484ae23bbf
commit 0bcaa0ebee

View file

@ -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;
}