You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 }=awaitact(()=>render(<TextAreaInput/>));// Works fine!getByRole('textbox')// throws an errorscreen.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.
The text was updated successfully, but these errors were encountered:
@testing-library/react
version:15.0.7
Bun test v1.1.21
@happy-dom/[email protected]
Relevant code or config:
test.setup.ts
Component.spec.tsx
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 writingafterEach(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 testSuggested solution:
just use the returned screen from the
render
function.The text was updated successfully, but these errors were encountered: