Getting ''Invariant Violation: Native module cannot be null.'' when i run the test

后端 未结 1 1149
深忆病人
深忆病人 2021-01-05 13:36

I have a Login component as below and I am writing some test cases for this component. When I tried to run the test I got the following error:

Test<

相关标签:
1条回答
  • 2021-01-05 14:15

    This problem happens when you import a native component in the render tree, as the test renderer do not have them. To fix this, either you need to mock the component (https://jestjs.io/docs/en/manual-mocks), or use shallow rendering (https://reactjs.org/docs/shallow-renderer.html)

    For your particular case, this is the github issue to help you: https://github.com/naoufal/react-native-safari-view/issues/99

    Another solution could be using react-native-mock-render module (the most active fork of react-native-mock)

    0 讨论(0)
提交回复
热议问题