Skip to content

fix: replace setTimeout with queueMicrotask to prevent deadlock#571

Merged
timdeschryver merged 1 commit into
testing-library:mainfrom
jonaskuske:fix/replace-settimeout-to-avoid-deadlock
Mar 11, 2026
Merged

fix: replace setTimeout with queueMicrotask to prevent deadlock#571
timdeschryver merged 1 commit into
testing-library:mainfrom
jonaskuske:fix/replace-settimeout-to-avoid-deadlock

Conversation

@jonaskuske

@jonaskuske jonaskuske commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

When using vitest, setTimeout is mocked and will only advance when instructed to do so (unless using vi.useFakeTimers({ shouldAdvanceTime: true }). This never happens when used within the testing library, leaving tests deadlocked. We can avoid that using queueMicrotask, which is not affected by mocked time.

closes #565

When using vitest, setTimeout is mocked and will only advance when instructed to do so. This never happens when used within the testing library, leaving tests deadlocked. We can avoid that using queueMicrotask, which is not affected by mocked time.

closes testing-library#565
@timdeschryver timdeschryver merged commit 906e8dd into testing-library:main Mar 11, 2026
6 checks passed
@timdeschryver

Copy link
Copy Markdown
Member

@all-contributors please add @jonaskuske for code

@allcontributors

Copy link
Copy Markdown
Contributor

@timdeschryver

I've put up a pull request to add @jonaskuske! 🎉

@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 19.1.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@NateRadebaugh

NateRadebaugh commented Mar 11, 2026

Copy link
Copy Markdown

@timdeschryver @jonaskuske can this please be backported to the branch of angular-testing-library that can be used in angular@20.x? I have a project not yet ready to update to angular 21 but I think we've been plagued by this bug for a while and want to confirm this resolves it for us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

waitFor not working when vi.useFakeTimers is used

3 participants