Run with Android
All packages have been linked successfully.
I have tried
$ ./gradlew clean #in android folder
$ react-native start
$ react-native run-android
then jest that show error
Invariant Violation: Native module cannot be null
$ jest
FAIL __tests__/SignInScreen-test.js
● Test suite failed to run
Invariant Violation: Native module cannot be null.
at invariant (node_modules/invariant/invariant.js:40:15)
at new NativeEventEmitter (node_modules/react-native/Libraries/EventEmitter/NativeEventEmitter.js:37:7)
at Object.<anonymous> (node_modules/react-native-reanimated/src/ReanimatedEventEmitter.js:4:16)
at Object.<anonymous> (node_modules/react-native-reanimated/src/core/AnimatedCall.js:2:1)
console.group node_modules/redux-logger/dist/redux-logger.js:1
action persist/PERSIST @ 05:17:04.459
console.log node_modules/redux-logger/dist/redux-logger.js:1
prev state {
authReducer: {
...
How can i fix this error or there are solutions to test React native app like Jest?
jestSetupFile.js
import mockAsyncStorage from '@react-native-community/async-storage/jest/async-storage-mock';
jest.mock('@react-native-community/async-storage', () => mockAsyncStorage);
jest.mock('react-native-keychain', () => ({
SECURITY_LEVEL_ANY: 'MOCK_SECURITY_LEVEL_ANY',
SECURITY_LEVEL_SECURE_SOFTWARE: 'MOCK_SECURITY_LEVEL_SECURE_SOFTWARE',
SECURITY_LEVEL_SECURE_HARDWARE: 'MOCK_SECURITY_LEVEL_SECURE_HARDWARE',
setGenericPassword: jest.fn().mockResolvedValue(),
getGenericPassword: jest.fn().mockResolvedValue(),
resetGenericPassword: jest.fn().mockResolvedValue(),
}));
package.json
"jest": {
"preset": "react-native",
"setupFiles": [
"./jestSetupFile.js"
]
},
SignInScreen-test.js
import {SignInScreen} from '../screens/SignInScreen';
describe('Test Component using hooks', () => {
test('SignInScreen', () => {
expect(<SignInScreen />).toMatchSnapshot();
});
});