Skip to content

fix(act): add try/catch around react-dom/test-utils require #340

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

Merged
merged 1 commit into from
Apr 1, 2019
Merged
Changes from all commits
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
8 changes: 7 additions & 1 deletion src/act-compat.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import React from 'react'
import ReactDOM from 'react-dom'
import {act as reactAct} from 'react-dom/test-utils'

let reactAct
try {
reactAct = require('react-dom/test-utils').act
Copy link
Collaborator

@alexkrolick alexkrolick Apr 1, 2019

Choose a reason for hiding this comment

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

Will this throw if act is not defined but the test-utils package is?

Copy link
Member Author

Choose a reason for hiding this comment

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

No it wont, but we'll handle it fine anyway thanks to the || below 👍

} catch (error) {
// ignore, this is to support old versions of react
}

// act is supported [email protected]
// so for versions that don't have act from test utils
Expand Down