I use react-router-dom
for routing in my React
application. Part of my app extracted in another package. List of dependencies looks like this:
I had this problem whilst testing and solved it by wrapping my test component with Routers.
import React from 'react';
import ReactDom from 'react-dom';
import Header from '../components/Header/Header';
import { BrowserRouter } from 'react-router-dom';
it('renders Header without crashing', () => {
const div = document.createElement('div');
ReactDom.render(
,
div);
ReactDom.unmountComponentAtNode(div);
});
Jest, Enzyme: Invariant Violation: You should not use or , To test a component (with Jest) that contains and withRouter you need to import Router in you test, not in your component import { BrowserRouter as Invariant Violation: You should not use or withRouter() outside a According to react router 4 docs, the components are considered valid, where I can create components composed of s, then import them into another component and place inside a .
https://xspdf.com/resolution/50584641.html