Closed xareelee closed 7 years ago
Looking at your stacktrace, it's actually calling out to react-native components, something react-native-mock stops. How have you setup react-native-mock in your tests?
Setup file for jest (as a test runner):
{
"jest": {
"preset": "react-native",
"setupFiles": [
"./.jest_init.js"
]
},
}
Inside the jest config file (whole code):
// .jest_init.js
// This will mutate `react-native`'s require cache with `react-native-mock`'s.
require('react-native-mock/mock'); // <-- side-effects!!!
// Why we need to import 'isomorphic-fetch'?
// See https://github.com/jefflau/jest-fetch-mock/issues/13
import 'isomorphic-fetch'
global.fetch = require('jest-fetch-mock');
I do not do something else with react-native-mock
or jest-fetch-mock
. I have not used mock objects yet; just include those libraries and set them up.
react-native-mock
isnt designed to work with jest, as jest contains it's own builtin mock. For this reason it shouldnt be used with it and will likely cause strange issues, as youre having
I'm developing React Native (RN) apps for iOS and Android.
I use storyshots/storybook to snapshot the vDOM(s) of RN components with specific props for UI tests.
However, Jest lacks the functionality to mimic RN events to test whether the buttons work correctly. Then I found airbnb's enzyme.
When I tested RN components with enzyme, I needed to install and set up react-native-mock. Then the issue happened:
Before I introduced react-native-mock to my project, I had an unsolved snapshot conflict.
After I add
react-native-mock
, the test error became:I think
react-native-mock
changes the behavior of storyshots, and make it report conflict incorrectly.I'll post this issue on both
storyshots
andreact-native-mock
.storyshots/issues/85