Skip to content

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

@JZalfen

Description

@JZalfen
  • @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions