Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

355
Views
Jest / react-testing-library / React - unable to find an element.. with async calls

I am getting this error, for this test:

Unable to find an element by: [data-testid="detail-result"]

import { render, screen, cleanup } from "@testing-library/react";
import { QueryClient, QueryClientProvider } from "react-query";
import Comp1 from "./Comp1";
import { DataProvider } from "./Context";

const queryClient = new QueryClient();

describe("Comp1 tests", () => {
  beforeEach(() => {
    jest.useFakeTimers();
  });

  it("Should give correct response with render", async () => {
    render(
      <QueryClientProvider client={queryClient}>
        <DataProvider>
          <Comp1 />
        </DataProvider>
      </QueryClientProvider>
    );
    expect(await screen.findByTestId("detail-result")).toBeInTheDocument();
  });
});

afterEach(cleanup);

I know it is something to do with the api call waiting for the other one to finish, but even with async/await I get the error:

recreated here: Sandbox

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!