Having `afterEach(cleanup)` in the test setup file breaks exported `screen` module on Bun test
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 50/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Tranquilo
- Stack tecnológico
- react, typescript
- Área
- frontend, testing-qa
Línea de trabajo
Comienza ejecutando bun test --preload test.setup.ts con test.setup.ts y Component.spec.tsx tal como se muestra. Rastrea cómo afterEach(cleanup) interactúa con el screen exportado y el documento utilizado por render. Se considera terminado cuando la reproducción puede usar el screen exportado manteniendo el cleanup del setup, con una prueba de regresión que cubra Bun.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
@testing-library/reactversion:15.0.7- Testing Framework and version:
Bun test v1.1.21 - DOM Environment:
@happy-dom/[email protected]
Relevant code or config:
test.setup.ts
import { GlobalRegistrator } from '@happy-dom/global-registrator';
import { cleanup } from '@testing-library/react';
import { expect, afterEach } from 'bun:test';
import * as matchers from '@testing-library/jest-dom/matchers';
GlobalRegistrator.register();
declare module 'bun:test' {
interface Matchers<T> extends matchers.TestingLibraryMatchers<any, void> {}
interface AsymmetricMatchers extends matchers.TestingLibraryMatchers<any, void> {}
}
expect.extend(matchers);
afterEach(cleanup);
Component.spec.tsx
import { act, render, screen } from '@testing-library/react';
import { TextAreaInput } from './TextAreaInput.component';
import { describe, it } from 'bun:test';
describe('TextAreaInput', () => {
it('Should show in the DOM', async () => {
const { getByRole } = await act(() => render(<TextAreaInput />));
// Works fine!
getByRole('textbox')
// throws an error
screen.getByRole('textbox');
// TypeError: For queries bound to document.body a global document has to be available... Learn more: https://testing-library.com/s/screen-global-error
});
});
What you did:
I'm just trying to test a component using the screen exported by react testing library using Bun test.
What happened:
everything was smooth, until I tried to use the screen exported from the react testing library it threw an error about "global document has to be available",
upon inspecting, removing afterEach(cleanup) from the test setup file or writing afterEach(cleanup) in each test file will make it works,
Reproduction:
just run bun test --preload test.setup.ts
Problem description:
using the screen exported while having the cleanup code in the test setup will break the test
Suggested solution:
just use the returned screen from the render function.
- 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 5 días. 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 76 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 302 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 319 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 77/100
apache/rocketmq-dashboard#6610 ·
Los mantenedores suelen responder en 3 días
-
ACK_WAITING HELP_WANTED UPDATE_CS
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
OWASP/CheatSheetSeries#2781 ·
Los mantenedores suelen responder en 1 día
-
Hermes: /ponytail off never reaches the model, the ruleset stays activePosiblemente ocupada @szsunyuan la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
DietrichGebert/ponytail#1121 ·
Los mantenedores suelen responder en 3 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
integrations plugin
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
mem0ai/mem0#7622 · 1 comentario ·
Los mantenedores suelen responder en 1 día