From 0bcaa0ebeefb384d7901fc122dfa8d273ca51c8d Mon Sep 17 00:00:00 2001 From: JoostK Date: Sun, 10 Mar 2024 22:13:04 +0100 Subject: [PATCH] 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 --- packages/private/testing/src/utils.ts | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/packages/private/testing/src/utils.ts b/packages/private/testing/src/utils.ts index 0092a621f0a..a077a659bdc 100644 --- a/packages/private/testing/src/utils.ts +++ b/packages/private/testing/src/utils.ts @@ -76,16 +76,9 @@ function wrapTestFn( 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; }