Skip to content
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

feat(waitFor): Automatically advance Jest fake timers #878

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

eps1lon
Copy link
Member

@eps1lon eps1lon commented Jul 19, 2022

What:

Closes #873

Why:

There's little value in waitFor if one has to advance timers by themselves.

How:

Copy implementation from @testing-library/dom.

There's an opportunity to write a more generic waitFor that we can share across Testing Library that specific host configs build on top on (e.g. also running MutationObserver in /dom). But that requires more coordination (starting with an extensive test suite). For now this hopefully suffices (pending testing in actual codebases).

Checklist:

  • Documentation updated
  • Tests
    • timing out
    • timing out without a callback error
    • switching to real timers
  • Test in actual codebase
  • Ready to be merged
  • Added myself to contributors table

@netlify
Copy link

netlify bot commented Jul 19, 2022

Deploy Preview for react-hooks-testing-library failed.

Name Link
🔨 Latest commit 18bfadf
🔍 Latest deploy log https://app.netlify.com/sites/react-hooks-testing-library/deploys/62d7140dcdefdf00088cc613

@eps1lon eps1lon force-pushed the feat/waitfor-jest-fake-timers branch from 30e6f0f to 18bfadf Compare July 19, 2022 20:28
// to resolve before continuing. We don't need to take advantage
// of parallelization so we're fine.
// https://stackoverflow.com/a/59243586/971592
await act(async () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is useless for React 17 and should be removed to not confuse. It is only needed in 18 where we need to remove the act from waitFor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tests timeout with jest fakeTimers and waitFor for on Promise.resolve calls
2 participants