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

Add tests for non-React discrete events flushing in a microtask #20772

Merged
merged 3 commits into from
Feb 9, 2021

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Feb 9, 2021

Adds some tests for #20748.

They're based on existing tests we have for React events. I converted the old tests to Hooks while I'm at it.

See individual commits.

I'm planning to copy paste so why not update them anyway.
These are still using React events. I'll change that next.
@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Feb 9, 2021
// Verify that the second button was removed.
await null;
expect(submitButtonRef.current).toBe(null);
// We'll assume that the browser won't let the user click it.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The original test was more interesting here because it fired an event and verified that React ignores it. However, if we fire an event manually on a DOM node, and listen directly on that node with a native listener, it would still fire. So I don't know what we should be testing here. I think just testing that the DOM node was removed is enough because the rest is up to the browser.

firstEvent.initEvent('click', true, true);
expect(() =>
dispatchAndSetCurrentEvent(disableButton, firstEvent),
).toErrorDev(['An update to Form inside a test was not wrapped in act']);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Using act would defeat the point of this test

Copy link
Contributor

Choose a reason for hiding this comment

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

Add as inline comment?

@sizebot
Copy link

sizebot commented Feb 9, 2021

Comparing: 97fce31...f945f3a

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js = 122.31 kB 122.31 kB = 39.42 kB 39.42 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 128.89 kB 128.89 kB = 41.46 kB 41.46 kB
facebook-www/ReactDOM-prod.classic.js = 406.62 kB 406.62 kB = 75.37 kB 75.37 kB
facebook-www/ReactDOM-prod.modern.js = 394.97 kB 394.97 kB = 73.49 kB 73.49 kB
facebook-www/ReactDOMForked-prod.classic.js = 406.63 kB 406.63 kB = 75.37 kB 75.37 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by 🚫 dangerJS against f945f3a

Copy link
Contributor

@acdlite acdlite left a comment

Choose a reason for hiding this comment

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

Looks great

@gaearon gaearon merged commit d919e2c into facebook:master Feb 9, 2021
koto pushed a commit to koto/react that referenced this pull request Jun 15, 2021
…book#20772)

* Convert some old discrete tests to Hooks

I'm planning to copy paste so why not update them anyway.

* Copy paste discrete tests into another file

These are still using React events. I'll change that next.

* Convert the test to use native events
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants