Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

356
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda