Skip to content

Commit

Permalink
Convert SyntheticWheelEvent-test.js to createRoot (facebook#28103)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcarrollcode authored and AndyPengc12 committed Apr 15, 2024
1 parent 686d5bf commit 806c62c
Showing 1 changed file with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,38 @@
'use strict';

let React;
let ReactDOM;
let ReactDOMClient;
let act;

describe('SyntheticWheelEvent', () => {
let container;
let root;

beforeEach(() => {
React = require('react');
ReactDOM = require('react-dom');
ReactDOMClient = require('react-dom/client');
act = require('internal-test-utils').act;

// The container has to be attached for events to fire.
container = document.createElement('div');
document.body.appendChild(container);
root = ReactDOMClient.createRoot(container);
});

afterEach(() => {
document.body.removeChild(container);
container = null;
});

it('should normalize properties from the MouseEvent interface', () => {
it('should normalize properties from the MouseEvent interface', async () => {
const events = [];
const onWheel = event => {
event.persist();
events.push(event);
};
ReactDOM.render(<div onWheel={onWheel} />, container);
await act(async () => {
root.render(<div onWheel={onWheel} />);
});

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

it('should normalize properties from the WheelEvent interface', () => {
it('should normalize properties from the WheelEvent interface', async () => {
const events = [];
const onWheel = event => {
event.persist();
events.push(event);
};
ReactDOM.render(<div onWheel={onWheel} />, container);

await act(async () => {
root.render(<div onWheel={onWheel} />);
});

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

it('should be able to `preventDefault` and `stopPropagation`', () => {
it('should be able to `preventDefault` and `stopPropagation`', async () => {
const events = [];
const onWheel = event => {
expect(event.isDefaultPrevented()).toBe(false);
Expand All @@ -92,7 +101,9 @@ describe('SyntheticWheelEvent', () => {
event.persist();
events.push(event);
};
ReactDOM.render(<div onWheel={onWheel} />, container);
await act(async () => {
root.render(<div onWheel={onWheel} />);
});

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

expect(events.length).toBe(2);
expect.assertions(5);
});
});

0 comments on commit 806c62c

Please sign in to comment.