enzyme: TypeError: Cannot read property 'current' of undefined
This happened after “enzyme-adapter-utils” was updated to version 1.10.0.
As well, I have import 'jsdom-global/register';
at the beginning of the test file.
API
- shallow
- mount
- render
Version
library | version |
---|---|
enzyme | 3.7.0 |
react | 16.6.3 |
react-dom | 16.6.3 |
react-test-renderer | 16.8.0 |
adapter (below) | 1.6.0 |
jsdom-global | 3.0.2 |
Adapter
- enzyme-adapter-react-16
- enzyme-adapter-react-16.3
- enzyme-adapter-react-16.2
- enzyme-adapter-react-16.1
- enzyme-adapter-react-15
- enzyme-adapter-react-15.4
- enzyme-adapter-react-14
- enzyme-adapter-react-13
- enzyme-adapter-react-helper
- others ( )
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 18
- Comments: 35 (6 by maintainers)
@benedyktdryl Updating React isn’t always an option.
I updated both react & react Dom 16.8.0 along with enzyme-react-adapter version 1.9.1, and I get
document is not defined
errorthe error:
Update your React to
16.8
.ReactCurrentDispatcher
is missing fromReactSharedInternals
in earlier releases whenreact-test-renderer
in16.8
is expecting it (probably because newer version ofenzyme-react-adapter
in1.9.1
is downloadingreact-test-renderer
in this version, due to not locked dependencies)I’ve been fighting with the
document is not defined
error for most of the morning. I got it working by rearranging things in my helper file. Note: I’m using AVA for my test runnerBefore (broken)
After (working)
My guess is the adapter is trying to access
document
during import.@tolumide-ng all react packages (including react-dom and react-test-renderer) must always have an identical minor version.
Hey We found a solution, which was:
"enzyme-adapter-react-16": "1.1.0"
to"enzyme-adapter-react-16.3": "1.6.1"
,import Adapter from 'enzyme-adapter-react-16
to Adapter fromenzyme-adapter-react-16.3
I updated those packages in my local branch and the original
find
error went away. Of course, it created a different error and invalidated over 60 snapshots. Yikes! It broke other tests, as well. Like I mentioned earlier, though, it’s not as simple as making a command decision to update npm packages.So, since this issue is closed, should I create a different issue to address my original problem?
You are correct @ljharb. I just overlooked it in the enormously long list of packages. 😉
Keeping the
react-test-renderer
version the same asreact
andreact-dom
.https://github.com/facebook/react/issues/14763#issuecomment-461016379
@Zveroboev every react package must always have an identical minor; so the fact that you’re using
react-test-render
16.8 will break, since you’re using react 16.6. You’ll need to peg that as a dev dep at~16.6
.If you’ve done that, and you’re still having an issue, I’ll reopen - if anyone else is having an issue, please file a separate one - and make sure all react packages have identical minor versions.
@benedyktdryl thanks, that update, plus adding the
--env=jsdom
to the test command fixed half of my test, now I get a different error.Cannot find module 'schedule/tracking' from 'ReactNativeRenderer-dev.js'
. I’m looking to see if I can find what this means.Is this to do with being a stateless component that you’re testing? We have the same issue, but its only happening on components that are not extending from
React.Component