Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/content/warnings/react-dom-test-utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The React Team recommends migrating your tests to [@testing-library/react](https
### ReactDOMTestUtils.renderIntoDocument {/*reactdomtestutilsrenderintodocument*/}

`renderIntoDocument` can be replaced with `render` from `@testing-library/react`.
Unlike `renderIntoDocument`, `render` gives you access to the rendered container and explicit cleanup APIs.

Before:

Expand All @@ -44,6 +45,22 @@ import {render} from '@testing-library/react';
render(<Component />);
```

`renderIntoDocument` rendered into a detached DOM node and returned the component instance instead of the container.
This made it difficult to inspect the rendered output or reliably clean it up after a test.
`render` returns helpers for the rendered tree, including `unmount`, and React Testing Library also provides `cleanup` to remove any trees mounted with `render` between tests.

```js
import {render} from '@testing-library/react';

test('renders a component', () => {
const {unmount} = render(<Component />);

// ...assertions...

unmount();
});
```

### ReactDOMTestUtils.Simulate {/*reactdomtestutilssimulate*/}

`Simulate` can be replaced with `fireEvent` from `@testing-library/react`.
Expand Down
Loading