Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Test based on `findByText` assertion fails after 551ms, despite default timeout being 1000ms

Abierto
#1,414 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
javascript, react, typescript
Área
testing-qa

Línea de trabajo

Comienza con la aserción screen.findByText proporcionada y las versiones indicadas de @testing-library/react 16.3.0, Vitest 3.2.4 y jsdom 26.1.0. Investiga, usando como contexto la documentación enlazada de findBy y el issue anterior, si el fallo alcanza el tiempo de espera documentado de 1000ms o si Vitest informa de la duración de forma inexacta. Se considera completado cuando se identifica el origen del fallo temprano intermitente o se documenta que es externo.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

  • @testing-library/react version: 16.3.0
  • Testing Framework and version: Vitest 3.2.4
  • DOM Environment: jsdom 26.1.0
Relevant code or config:
expect(
  await screen.findByText(
    "text which is supposed to be found after loading state is passed",
  ),
).toBeInTheDocument();
What you did:

Ran a test which failed on this assertion. Only sometimes. Typically in CI (Github Actions).

What happened:

× path/to/my.test.tsx > x > shows expected content 551ms
→ expect(element).toBeInTheDocument()
element could not be found in the document
⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯
FAIL path/to/my.test.tsx > x > shows expected content
Error: expect(element).toBeInTheDocument()
element could not be found in the document

Reproduction:

Does not reproduce easily. Is flaky. Trying to understand if there is some misunderstanding in how things are supposed to work.

Problem description:

When running a test based on findBy, we sometimes find them to be flaky. It is sometimes resolved by using waitForElementToBeRemoved on the previous state, but that just adds another possible race condition, and also tends to be flaky.

I expect the test to run for at least 1000ms (as per findBy logic documented here), but sometimes find that the test fails much sooner (after 551 ms in the example above).

Suggested solution:

I'm trying to deduce a cause here for further investigation.

  • Is findBy resolving sooner than expected? If yes, it seems like a problem internal to the library, possibly https://github.com/testing-library/react-testing-library/issues/865?
  • Is the (vitest) reported time unreliable, and we may have hit the 1000ms timeout despite 551ms being reported? If so, maybe extending the default timeout could be beneficial, even though hundreds of similar tests tend to pass every time, so it seems odd.

Overall, this seems like a strange problem, and I'm not expecting a straight-forward fix, but would like you to know about it, and would be grateful for any pointers on how to analyze further.

Lenguaje dominante
JavaScript
Estrellas
19.7k
Forks
1.2k
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de testing-library/react-testing-library

Todos los issues de testing-library/react-testing-library

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.