Invariant Violation: You should not use outside a

后端 未结 10 1418
没有蜡笔的小新
没有蜡笔的小新 2021-02-01 00:30

I have a problem that I don\'t know how to solve, I get this error when running npm test

Invariant Violation: You should not use

10条回答
  •  终归单人心
    2021-02-01 01:18

    The proper way to handle this, according to React Router devs, is to wrap your unit test in a Router. Using MemoryRouter is recommended in order to be able to reset the router between tests.

    You can still do something like the following:

    
      
    
    

    Then in App:

    
      
      
    
    

    Your unit tests for App would normally be something like:

    const content = render(); // Fails Unit test
    

    Update the unit test to:

    const content = render(); // Passes Unit test
    

提交回复
热议问题