New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(core): ensure async tests are awaited properly #54801
Conversation
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.
0c427a4
to
505a633
Compare
return function (done: DoneFn) { | ||
if (typeof blockFn === 'function') { | ||
elementGetter().innerHTML = html; | ||
const blockReturn = blockFn(); | ||
if (blockReturn instanceof Promise) { | ||
if ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at it again, it may be possible to drop the done
parameter altogether and just return the promise to Jasmine for it to take care of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If Jasmine recognises returned promises (I assume it does) - than this makes sense to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Yeah, I wonder if we can just return a promise instead, but can follow-up on that
Caretaker note: Existing failures that got fixed via: #54791 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I agree that we could just return a promise but let's merge it as-is to unblock the CI / local tests
This commit addresses a typing mismatch, where these functions were declared to return whichever value their callback returned, but this was inaccurate: it's always a test callback function with `done` argument.
The `runCallbackOnce` closure is declared not to have any parameters itself, so it is compatible as `queueMicrotask` callback without the extra closure. This reduces the call stack by a frame and avoids the extra closure allocation.
505a633
to
6f7843c
Compare
This PR was merged into the repository by commit d269c88. |
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 issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
See individual commits.
Example failure: https://github.com/angular/angular/actions/runs/8222559168/job/22484218605?pr=54800