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

fix(fireEvent): automatically configure fireEvent to be wrapped in act #685

Merged
merged 2 commits into from Jun 1, 2020

Conversation

kentcdodds
Copy link
Member

@kentcdodds kentcdodds commented Jun 1, 2020

What: fix(fireEvent): automatically configure fireEvent to be wrapped in act

Why: Because now we don't have to do this nonsense:

// react-testing-library's version of fireEvent will call
// dom-testing-library's version of fireEvent wrapped inside
// an "act" call so that after all event callbacks have been
// called, the resulting useEffect callbacks will also be
// called.
function fireEvent(...args) {
let returnValue
act(() => {
returnValue = dtlFireEvent(...args)
})
return returnValue
}
Object.keys(dtlFireEvent).forEach(key => {
fireEvent[key] = (...args) => {
let returnValue
act(() => {
returnValue = dtlFireEvent[key](...args)
})
return returnValue
}
})

It also means that fireEvent will be globally configured to be wrapped in act so even if people import the DOM Testing Library one (like we do in @testing-libary/user-event), it will be wrapped in act (assuming they've also imported @testing-library/react).

One note is that pure.js is not actually pure and never was because it configures DOM Testing Library globally. Perhaps in the future we should make a breaking change to make pure.js actually pure.

How:

Checklist:

  • Documentation added to the N/A
  • Tests N/A (though I did verify that the one test we had to ensure act was called correctly is still passing)
  • Typescript definitions updated N/A
  • Ready to be merged

Now not only will React Testing Library's fireEvent be wrapped in
act, but so will DOM Testing Library's fireEvent (if
@testing-library/react is imported). It works very similar to async
act for the asyncWrapper config.

Closes: testing-library/user-event#188
Closes: testing-library/user-event#255
Reference: https://github.com/testing-library/user-event/issues/277

Now not only will React Testing Library's `fireEvent` be wrapped in
`act`, but so will DOM Testing Library's `fireEvent` (if
`@testing-library/react` is imported). It works very similar to async
act for the `asyncWrapper` config.

Closes: testing-library/user-event#188
Closes: testing-library/user-event#255
Reference: https://github.com/testing-library/user-event/issues/277
@codesandbox-ci
Copy link

codesandbox-ci bot commented Jun 1, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 1e2e113:

Sandbox Source
dazzling-frog-z6ekz Configuration
sparkling-water-dksp0 Configuration

@codecov
Copy link

codecov bot commented Jun 1, 2020

Codecov Report

Merging #685 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #685   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         4    +1     
  Lines          101        99    -2     
  Branches        15        15           
=========================================
- Hits           101        99    -2     
Impacted Files Coverage Δ
src/fire-event.js 100.00% <100.00%> (ø)
src/pure.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7b7460a...1e2e113. Read the comment docs.

@kentcdodds kentcdodds merged commit 6147830 into master Jun 1, 2020
@kentcdodds kentcdodds deleted the pr/fire-event-act branch June 1, 2020 23:33
@kentcdodds
Copy link
Member Author

🎉 This PR is included in version 10.0.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
1 participant