[BUG] Enzyme mount() throws a "No `ref` found." error
See original GitHub issueDescription
Testing mounted motion elements using enzyme mount() throws a ref error that pertains to forwardingRefs:
Error: Uncaught [Error: No 'ref' found. Ensure components created with
motion.custom forward refs using 'React.forwardRef']
CodeSandbox: https://codesandbox.io/s/mounting-motion-elements-dz7oh
Steps to reproduce
Steps to reproduce the behavior:
- Open codesandbox link.
- Run the tests.
- Check the console.
- The test that mounts the motion component will throw an exeption, while the test that shallows works as expected.
Expected behavior Enzyme should be able to successfully mount the component without throwing an exception.
Additional Information In addition to the codesandbox I have also tested the issue using the following dependency versions in my own codebase using the following:
- “react”: “16.8.4”,
- “react-dom”: “16.8.4”,
- “react-test-renderer”: “16.8.4”,
- “framer-motion”: “1.16.15”,
- “mocha”: “5.2.0”,
- “chai”: “4.1.2”,
- “enzyme”: “3.10.0”,
- “enzyme-adapter-react-16”: “1.14.0”
Issue Analytics
- State:
- Created 4 years ago
- Reactions:8
- Comments:10
Top Results From Across the Web
Change Log · Enzyme - GitHub Pages
mount : extract MountedTraversal.hasClassName from MountedTraversal.instHasClassName, which allows ReactWrapper. · withDom : Display a useful error when withDom ...
Read more >Continuous integration for React applications using Jest and ...
Learn how to implement continuous integration for React applications using Jest and Enzyme.
Read more >Jest test fails : TypeError: window.matchMedia is not a function
In this project, I'm using Jest snapshot testing and got an error TypeError: window.matchMedia is not a function inside my component. I go ......
Read more >Fix the "not wrapped in act(...)" warning - Kent C. Dodds
setState({status: 'rejected', error: e}) } } render() { const {error, ... So while the warning would probably help people find and fix bugs...
Read more >React Testing with Airbnb's Enzyme, Jest and Babel
If it does not throw an error and it passed then your good to go. What's the difference between shallow rendering and full...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m having the same issue when using react-test-renderer’s create() method directly:
CodeSandbox: https://codesandbox.io/s/mounting-motion-elements-n2elg
Any ideas?
@andrefox333 Just a super simple mock where
motion.div
becomes a simplediv
, etc.I just mocked
div
andimg
, as those are the only two “elements” we’re currently using. If you’re using a lot of motion elements (e.g.motion.ul
,motion.li
,motion.whatever
) then you could return a proxy with a generic get method that returns an object of the same type as requested, e.g.motion.ul
>ul