After updating react native from version 0.66 to version 0.71.0 with the help of the Upgrade Helper from the official website, the entire application worked normally.
However, the tests no longer worked.
This was probably due to Jest or babel lib updates. But I’m still not sure.
It is worth saying that, what actually happens is that: jest, apparently, no longer ignores the libs informed in transformIgnorePatterns and because of that, several parts of the test, end up breaking, informing that a certain import is undefined, when in reality, that particular imported lib was supposed to be ignored.
It is worth mentioning that even react native components are not being recognized now, after the update.
Below are most of the updates that have occurred in the application:
(https://i.stack.imgur.com/zzppz.png)
(https://i.stack.imgur.com/mF2RH.png)
Error generated after running a simple test on the login screen
Test suite failed to run
TouchableOpacity is not available in the currently-installed version of react-native
48 | };
49 |
> 50 | export const RButtonPrimary = styled.TouchableOpacity`
| ^
51 | height: 50px;
52 | padding: 10px;
53 | ${props => buttonThemeColor[props.theme]};
The error refers to this part of the code:
export const RButtonPrimary = styled.TouchableOpacity`
height: 50px;
padding: 10px;
${props => buttonThemeColor[props.theme]};
border-radius: 10px;
align-self: stretch;
align-items: center;
justify-content: center;
`;
Our jest.config.js:
module.exports = {
bail: true,
clearMocks: true,
collectCoverage: true,
preset: 'react-native',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
transform: {
'^.+\.(js|ts|jsx|tsx)$': 'babel-jest',
},
transformIgnorePatterns: [
'node_modules/(?!(@react-native|react-native' +
'|react-navigation-tabs' +
'|react-native-splash-screen' +
'|react-native-screens' +
'|react-native-date-picker' +
'|react-native-reanimated' +
'|react-native-vector-icons' +
'|react-native-gesture-handler' +
'|@react-native-community' +
'|@react-navigation' +
'|@react-navigation/stack' +
'|react-native-iphone-x-helper' +
'|react-native-rate' +
')/)',
],
setupFiles: [
'./__tests__/mocks/rn-device-info.setup.js',
'./__tests__/mocks/flashmessage.setup.js',
'./__tests__/mocks/rn-elements.setup.js',
'./__tests__/mocks/rn-dash.setup.js',
'./__tests__/mocks/rn-snap-carousel.setup.js',
'./__tests__/mocks/rn-netinfo.setup.js',
'./__tests__/mocks/rn-woodpicker.setup.js',
'./__tests__/mocks/rn-gesture-handler.setup.js',
'./__tests__/mocks/alertmsg.setup.js',
'./__tests__/mocks/touchableopacity.setup.js',
'./__tests__/mocks/async.storage.setup.js',
'./__tests__/mocks/navigation.native.setup.js',
'./__tests__/mocks/auth.context.setup.js',
'./__tests__/mocks/notification.context.setup.js',
'./__tests__/mocks/content.payslip.resume.inf.setup.js',
'./__tests__/mocks/webview.setup.js',
'./__tests__/mocks/sentry.setup.js',
'./__tests__/mocks/react-native-device-info.setup.js',
'./__tests__/mocks/rn-keyboard-aware-scroll-view.setup.js',
'./__tests__/mocks/sleep.setup.js',
'./__tests__/mocks/usedarkmode.setup.js',
'./__tests__/mocks/saveEvent.setup.js',
'./__tests__/mocks/geolocation-service.setup.js',
],
setupFilesAfterEnv: ['./__tests__/mocks/geolocation-service.setup.js'],
collectCoverageFrom: [
'src/pages/**/*.js',
'!src/pages/**/styles.js',
'src/pages/**/*.tsx',
'!src/pages/**/styles.ts',
'!src/services/api.js',
'!src/config/ReactotronConfig.js',
],
coverageReporters: ['json', 'lcov'],
coverageDirectory: '__tests__/coverage',
moduleNameMapper: {
'^~/(.*)': '<rootDir>/src/$1',
},
testMatch: ['**/__tests__/**/*.test.js'],
maxWorkers: 3,
globals: {
'ts-jest': {
diagnostics: false,
isolatedModules: true,
},
},
};