Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert SyntheticWheelEvent-test.js to createRoot #28103

Merged
merged 3 commits into from
Jan 26, 2024
Merged
Changes from 1 commit
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
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 () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can add an expect.assertions(3) to the end of this test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the expected number of assertions be 5? 2x for each dispatchEvent call (4 total) and one expect events to be "2".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I counted wrong

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 Down