React router's Link component is not found as expected when test runs for first time
See original GitHub issueCurrent behavior
Testing a component with shallow and dive and searching for react-router’s Link
component fails only the first time, after that Jest uses its cache and works perfectly.
In the first run Link
can be found as e
instead.
Expected behavior
Link
should be found seamlessly.
Your environment
API
- shallow
Version
library | version |
---|---|
enzyme | 3.10.0 |
react | 16.8.6 |
react-dom | 16.8.6 |
react-router | 5.0.1 |
react-redux | 7.0.3 |
adapter (below) | 1.14.0 |
Adapter
- [X ] enzyme-adapter-react-16
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
React router's Link component is not found as expected when ...
Try finding by constructor, instead of using the name. It's possible that react router's Link's display name isn't set properly.
Read more >Routing not working as expected in React app using react ...
The code for my RootPage component is as follows: import { Link } from 'react-router-dom'; const RootPage = () => { return (...
Read more >Testing - React Router: Declarative Routing for React.js
Testing. React Router relies on React context to work. This affects how you can test your components that use our components.
Read more >Test Renderer - React
This package provides a React renderer that can be used to render React components to pure JavaScript objects, without depending on the DOM...
Read more >React Router v5: The Complete Guide - SitePoint
You can place your <Route> component anywhere you want your route to be rendered. Since <Route> , <Link> and all the other React...
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 Free
Top 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
sorry, it was, i just missed it 😃
lmk what it ends up being. I’m going to close this for now (with a recommendation to always find by constructor and not by display name), but am happy to reopen if there’s something actionable in enzyme.
Actually after that first time it is correctly found as
Link
so the display name seems to be ok. Searching by constructor works fine.