@samitouri / QOS-React-1 / commits / fbb21066a2

Convert SyntheticWheelEvent-test.js to createRoot (#28103)

Matt Carroll committed Jan 26, 2024 at 00:05 UTC fbb21066a2117c7cfbbca21260d2d9f3b2973286
1 file changed +20 -8
packages/react-dom/src/events/__tests__/SyntheticWheelEvent-test.js
+20 -8
@@ -10,18 +10,22 @@
10 'use strict';
11
12 let React;
13 -let ReactDOM;
13 +let ReactDOMClient;
14 +let act;
15
16 describe('SyntheticWheelEvent', () => {
17 let container;
18 + let root;
19
20 beforeEach(() => {
21 React = require('react');
20 - ReactDOM = require('react-dom');
22 + ReactDOMClient = require('react-dom/client');
23 + act = require('internal-test-utils').act;
24
25 // The container has to be attached for events to fire.
26 container = document.createElement('div');
27 document.body.appendChild(container);
28 + root = ReactDOMClient.createRoot(container);
29 });
30
31 afterEach(() => {
@@ -29,13 +33,15 @@ describe('SyntheticWheelEvent', () => {
33 container = null;
34 });
35
32 - it('should normalize properties from the MouseEvent interface', () => {
36 + it('should normalize properties from the MouseEvent interface', async () => {
37 const events = [];
38 const onWheel = event => {
39 event.persist();
40 events.push(event);
41 };
38 - ReactDOM.render(<div onWheel={onWheel} />, container);
42 + await act(async () => {
43 + root.render(<div onWheel={onWheel} />);
44 + });
45
46 container.firstChild.dispatchEvent(
47 new MouseEvent('wheel', {
@@ -48,13 +54,16 @@ describe('SyntheticWheelEvent', () => {
54 expect(events[0].button).toBe(1);
55 });
56
51 - it('should normalize properties from the WheelEvent interface', () => {
57 + it('should normalize properties from the WheelEvent interface', async () => {
58 const events = [];
59 const onWheel = event => {
60 event.persist();
61 events.push(event);
62 };
57 - ReactDOM.render(<div onWheel={onWheel} />, container);
63 +
64 + await act(async () => {
65 + root.render(<div onWheel={onWheel} />);
66 + });
67
68 let event = new MouseEvent('wheel', {
69 bubbles: true,
@@ -83,7 +92,7 @@ describe('SyntheticWheelEvent', () => {
92 expect(events[1].deltaY).toBe(-50);
93 });
94
86 - it('should be able to `preventDefault` and `stopPropagation`', () => {
95 + it('should be able to `preventDefault` and `stopPropagation`', async () => {
96 const events = [];
97 const onWheel = event => {
98 expect(event.isDefaultPrevented()).toBe(false);
@@ -92,7 +101,9 @@ describe('SyntheticWheelEvent', () => {
101 event.persist();
102 events.push(event);
103 };
95 - ReactDOM.render(<div onWheel={onWheel} />, container);
104 + await act(async () => {
105 + root.render(<div onWheel={onWheel} />);
106 + });
107
108 container.firstChild.dispatchEvent(
109 new MouseEvent('wheel', {
@@ -111,5 +122,6 @@ describe('SyntheticWheelEvent', () => {
122 );
123
124 expect(events.length).toBe(2);
125 + expect.assertions(5);
126 });
127 });