Skip to content

Commit 9be365e

Browse files
committed
Document why the render wrapper and setup import exist in render.tsx
Add explicit comments explaining that tests must import from this module (not directly from @testing-library/react) to ensure the ./setup side-effects run first: ResizeObserver polyfill, Event/CustomEvent alignment with jsdom, and afterEach(cleanup) registration.
1 parent 5b67922 commit 9be365e

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

app/test/helpers/ui/render.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import * as React from 'react'
2+
3+
// This import MUST stay here — it runs side-effects that every UI test needs:
4+
// polyfilling ResizeObserver, aligning globalThis.Event/CustomEvent with jsdom,
5+
// and registering an afterEach(cleanup) hook. Tests should never import
6+
// '@testing-library/react' directly; they should import from this module
7+
// instead so these side-effects are guaranteed to run first.
28
import './setup'
9+
310
import {
411
fireEvent,
512
render as rtlRender,
@@ -11,6 +18,14 @@ import {
1118

1219
type UIErrorRenderOptions = Omit<RenderOptions, 'queries'>
1320

21+
/**
22+
* Thin wrapper around Testing Library's render.
23+
*
24+
* This exists so that every test imports from this module rather than directly
25+
* from '@testing-library/react'. Importing from here guarantees the './setup'
26+
* side-effects (ResizeObserver polyfill, Event/CustomEvent alignment, and
27+
* afterEach cleanup) have already executed before any component is rendered.
28+
*/
1429
export function render(
1530
element: React.ReactElement,
1631
options?: UIErrorRenderOptions

0 commit comments

Comments
 (0)