I'm having issue while running npm test it shows this error in terminal and it's happening with only the @react-navigation/drawer:
● Test suite failed to run
TypeError: (0 , _drawer.createDrawerNavigator) is not a function 13 | 14 | const Stack = createStackNavigator(); > 15 | const Drawer = createDrawerNavigator(); | ^ 16 | 17 | import AddUser from './src/screens/AddUserScreens/AddUser'; 18 | import SuccessScreen from './src/screens/CommonScreens/Success'; at Object.<anonymous> (App.js:15:16) at Object.<anonymous> (__tests__/App-test.js:7:1)
I'm using jest and react-native-testing-library package and also added jest setup file and added the following:
import React from 'react';
jest.mock('react-native-reanimated', () =>
require('react-native-reanimated/mock'),
);
jest.mock(
'@react-navigation/drawer',
async () =>
await {
createDrawerNavigator: jest.fn().mockReturnValue({
Navigator: ({children}) => <>{children}</>,
Screen: ({children}) => <>{children}</>,
}),
},
);
here is my jest preset
"jest": {
"preset": "react-native",
"setupFiles": [
"./node_modules/react-native-gesture-handler/jestSetup.js",
"./jest-setup.js"
],
"setupFilesAfterEnv": [
"@testing-library/jest-native/extend-expect"
],
"transformIgnorePatterns": [
"node_modules/(?!(jest-)?react-native|native-base-.*|@react-native-community|@react-navigation)"
],
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js"
}
}
Dependencies
"dependencies": {
"@react-native-community/checkbox": "^0.4.1",
"@react-native-community/masked-view": "^0.1.10",
"@react-navigation/drawer": "^5.8.2",
"@react-navigation/native": "^5.5.0",
"@react-navigation/stack": "^5.4.1",
"native-base": "^2.13.12",
"react": "16.11.0",
"react-native": "0.62.2",
"react-native-gesture-handler": "^1.6.1",
"react-native-reanimated": "^1.9.0",
"react-native-safe-area-context": "^3.0.2",
"react-native-screens": "^2.8.0",
"react-native-simple-radio-button": "^2.7.4",
"react-native-vector-icons": "^6.6.0"
},
"devDependencies": {
"@babel/core": "^7.6.2",
"@babel/runtime": "^7.6.2",
"@react-native-community/eslint-config": "^0.0.5",
"@testing-library/jest-native": "^3.1.0",
"babel-jest": "^24.9.0",
"eslint": "^6.5.1",
"jest": "^24.9.0",
"metro-react-native-babel-preset": "^0.58.0",
"react-native-testing-library": "^2.1.0",
"react-test-renderer": "16.11.0"
},