Skip to content

Commit fbb2106

Browse files
Convert SyntheticWheelEvent-test.js to createRoot (#28103)
1 parent 9bad8ed commit fbb2106

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

packages/react-dom/src/events/__tests__/SyntheticWheelEvent-test.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,38 @@
1010
'use strict';
1111

1212
let React;
13-
let ReactDOM;
13+
let ReactDOMClient;
14+
let act;
1415

1516
describe('SyntheticWheelEvent', () => {
1617
let container;
18+
let root;
1719

1820
beforeEach(() => {
1921
React = require('react');
20-
ReactDOM = require('react-dom');
22+
ReactDOMClient = require('react-dom/client');
23+
act = require('internal-test-utils').act;
2124

2225
// The container has to be attached for events to fire.
2326
container = document.createElement('div');
2427
document.body.appendChild(container);
28+
root = ReactDOMClient.createRoot(container);
2529
});
2630

2731
afterEach(() => {
2832
document.body.removeChild(container);
2933
container = null;
3034
});
3135

32-
it('should normalize properties from the MouseEvent interface', () => {
36+
it('should normalize properties from the MouseEvent interface', async () => {
3337
const events = [];
3438
const onWheel = event => {
3539
event.persist();
3640
events.push(event);
3741
};
38-
ReactDOM.render(<div onWheel={onWheel} />, container);
42+
await act(async () => {
43+
root.render(<div onWheel={onWheel} />);
44+
});
3945

4046
container.firstChild.dispatchEvent(
4147
new MouseEvent('wheel', {
@@ -48,13 +54,16 @@ describe('SyntheticWheelEvent', () => {
4854
expect(events[0].button).toBe(1);
4955
});
5056

51-
it('should normalize properties from the WheelEvent interface', () => {
57+
it('should normalize properties from the WheelEvent interface', async () => {
5258
const events = [];
5359
const onWheel = event => {
5460
event.persist();
5561
events.push(event);
5662
};
57-
ReactDOM.render(<div onWheel={onWheel} />, container);
63+
64+
await act(async () => {
65+
root.render(<div onWheel={onWheel} />);
66+
});
5867

5968
let event = new MouseEvent('wheel', {
6069
bubbles: true,
@@ -83,7 +92,7 @@ describe('SyntheticWheelEvent', () => {
8392
expect(events[1].deltaY).toBe(-50);
8493
});
8594

86-
it('should be able to `preventDefault` and `stopPropagation`', () => {
95+
it('should be able to `preventDefault` and `stopPropagation`', async () => {
8796
const events = [];
8897
const onWheel = event => {
8998
expect(event.isDefaultPrevented()).toBe(false);
@@ -92,7 +101,9 @@ describe('SyntheticWheelEvent', () => {
92101
event.persist();
93102
events.push(event);
94103
};
95-
ReactDOM.render(<div onWheel={onWheel} />, container);
104+
await act(async () => {
105+
root.render(<div onWheel={onWheel} />);
106+
});
96107

97108
container.firstChild.dispatchEvent(
98109
new MouseEvent('wheel', {
@@ -111,5 +122,6 @@ describe('SyntheticWheelEvent', () => {
111122
);
112123

113124
expect(events.length).toBe(2);
125+
expect.assertions(5);
114126
});
115127
});

0 commit comments

Comments
 (0)