`waitFor` utils are not wrapped in `act` so some state updates are not applied to the DOM
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
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- javascript, react
Línea de trabajo
Comienza con el async wrapper pasado a DOM Testing Library y con el uso de waitForElementToBeRemoved mostrado en App.test.tsx. Revisa el commit enlazado que eliminó la llamada directa a act y utiliza la reproducción de StackBlitz para verificar que la actualización final del estado se aplica al DOM sin un async act explícito.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
@testing-library/reactversion: 16.3.0- Testing Framework and version: jest 30.1.3
- DOM Environment: jsdom 26.1.0
Relevant code or config:
test('it loads', async () => {
render(<App />);
await waitForElementToBeRemoved(screen.queryByRole('progressbar'));
// Commenting this out fails the test
// await act(() => new Promise((r) => setTimeout(r, 0)));
expect(screen.getByText('Loaded')).toBeDefined();
});
What you did:
Upgrading to React 18 along with react testing library v14, I found that some of my tests were now failing unless I add an explicit async act.
Digging into it, it seems to be this change to the async wrapper passed to the dom testing library where it no longer directly calls act, so state updates from the final iteration of the waitFor are not flushed to the DOM.
It looks like it only flushes the microtask queue, which won't give react an opportunity to process this state update.
Reproduction:
I'm using React 18 and RTL 14 but I've reproduced it on React 19 and RTL 16.
https://stackblitz.com/edit/rtl-template-4a3jt9jx?file=src%2FApp.test.tsx&view=editor
Suggested solution:
I don't have enough knowledge of the codebase to understand why the call to act was removed.
- Lenguaje dominante
- JavaScript
- Estrellas
- 19.7k
- Forks
- 1.2k
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de testing-library/react-testing-library
-
fireEvent.select does not wrap its automatic native focus in actPosiblemente ocupada @sergioperezcheco la tomó hace 1 día. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
-
bug: calling configure() without reactStrictMode resets it to undefined, silently disabling strict modeQuizá libre de nuevo @suhailopensource la tomó hace 72 días y no hay ningún pull request abierto. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 35/100
testing-library/react-testing-library#1466 · 1 comentario ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 30/100
testing-library/react-testing-library#1459 · 2 comentarios ·
-
perf: optimize container lookup with early exitQuizá libre de nuevo @Ch-Abhinav-Chowdary la tomó hace 298 días y no hay ningún pull request abierto. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 35/100
testing-library/react-testing-library#1430 · 1 comentario ·
-
`fireEvent.mouseEnter` does not forward `relatedTarget` (relatedTarget is the window instead)Posiblemente ocupada @swarnim02 la tomó hace 315 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 55/100
Todos los issues de testing-library/react-testing-library
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
`yarn vitest:update` (documented) throws locally; local Cypress scripts target an unserved portAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
rescript-lang/rescript-lang.org#1415 ·
Los mantenedores suelen responder en 2 días
-
[Bug]: agent capture drops long Unicode text as punctuationPosiblemente ocupada @ktz03 la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
volcengine/OpenViking#5801 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Deepak3699/Ai_Mentor#244 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
nextcloud/collectives#2843 ·
Los mantenedores suelen responder en 1 día