Invariant failed: You should not use outside a

后端 未结 20 1386
伪装坚强ぢ
伪装坚强ぢ 2020-12-03 20:55

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:

20条回答
  •  抹茶落季
    2020-12-03 21:11

    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

提交回复
热议问题