Skip to content

Commit

Permalink
No diff syntax highlighting available
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Mar 27, 2024
1 parent a19311b commit 169020f
Showing 1 changed file with 39 additions and 15 deletions.
54 changes: 39 additions & 15 deletions src/content/warnings/react-dom-test-utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ title: react-dom/test-utils Deprecation Warnings

## ReactDOMTestUtils.act() warning {/*reactdomtestutilsact-warning*/}

`act` from `react-dom/test-utils` has been deprecated in favor of `act` from `react`:
`act` from `react-dom/test-utils` has been deprecated in favor of `act` from `react`.

```diff
-import {act} from 'react-dom/test-utils';
+import {act} from 'react';
Before:

```js
import {act} from 'react-dom/test-utils';
```

After:

```js
import {act} from 'react';
```

## Rest of ReactDOMTestUtils APIS {/*rest-of-reactdomtestutils-apis*/}
Expand All @@ -19,27 +26,44 @@ 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`:
`renderIntoDocument` can be replaced with `render` from `@testing-library/react`.

```diff
-import {renderIntoDocument} from 'react-dom/test-utils';
+import {render} from '@testing-library/react';
Before:

-renderIntoDocument(<Component />);
+render(<Component />);
```js
import {renderIntoDocument} from 'react-dom/test-utils';

renderIntoDocument(<Component />);
```

After:

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

render(<Component />);
```

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

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

```diff
-import {Simulate} from 'react-dom/test-utils';
+import {fireEvent} from '@testing-library/react';
Before:

```js
import {Simulate} from 'react-dom/test-utils';

const element = document.querySelector('button');
Simulate.click(element);
```

After:

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

const element = document.querySelector('button');
-Simulate.click(element);
+fireEvent.click(element);
fireEvent.click(element);
```

Be aware, that `fireEvent` dispatches an actual event on the element and doesn't just synthetically call the event handler.
Expand Down

0 comments on commit 169020f

Please sign in to comment.