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

When using "useFakeTimers", "findBy*" queries aren't resolved #1218

Closed
JZalfen opened this issue Feb 21, 2023 · 3 comments
Closed

When using "useFakeTimers", "findBy*" queries aren't resolved #1218

JZalfen opened this issue Feb 21, 2023 · 3 comments

Comments

@JZalfen
Copy link

JZalfen commented Feb 21, 2023

  • @testing-library/dom version: 9.0.0
  • Testing Framework and version: vitest version: 0.28.5 with @testing-library/react version: 14.0.0
  • DOM Environment: jsdom version: 21.1.0

Relevant code or config:

it('with fake timers, not working :(', async () => {
  vi.useFakeTimers();

  render(<TestComponent />);

  screen.getByText('Apple');
  vi.runOnlyPendingTimers();

  // this promise never resolves with fake timers
  await screen.findByText('Pear');

  // restore to real timers
  vi.useRealTimers();
});

What you did:

Using "useFakeTimers" with "findBy*" queries.

What happened:

Timeout on first usage of "screen.findByText".

Reproduction:

Stackblitz: https://stackblitz.com/edit/vitejs-vite-fwc91c?file=src/TestComponent.spec.tsx
To run test: execute "vitest" in terminal

Problem description:

The test runs into a timeout.

Suggested solution:

none

@bc-m
Copy link

bc-m commented Feb 21, 2023

With @testing-library/react version 13.4.0 (using @testing-library/dom version 8.20.0) it works.

Stackblitz: https://stackblitz.com/edit/vitejs-vite-mfzplb?file=src/TestComponent.spec.tsx

So it looks like a regression of @testing-library/dom version 9.

@bc-m
Copy link

bc-m commented Feb 22, 2023

For me vi.useFakeTimers({ shouldAdvanceTime: true }); fixed it for @testing-library/dom v9:

https://stackblitz.com/edit/vitejs-vite-jjkbqn?file=src/TestComponent.spec.tsx

@eps1lon
Copy link
Member

eps1lon commented Mar 8, 2023

We don't support automatic advancement of fake timers outside of Jest. Closing as a duplicate of #987

@eps1lon eps1lon closed this as not planned Won't fix, can't repro, duplicate, stale Mar 8, 2023
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

No branches or pull requests

3 participants