Is it possible to use jest in react-native
projects, which use components from react-native-elements
?
The example jest file https://github.com/vanGalilea/react-native-testing/blob/master/tests/Login.test.tsx works fine as it is. As soon as I change the <Text>
component from the react-native
version to the react-native-elements
version, I get the following error message.
● Test suite failed to run
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
By default "node_modules" folder is ignored by transformers.
Here's what you can do:
....
....
Details:
C:\react\testingLibrary\node_modules\react-native-elements\dist\index.js:6
import Button from './buttons/Button';
^^^^^^
SyntaxError: Cannot use import statement outside a module
I added the following line to the jest.config.js
file.
transformIgnorePatterns: ['node_modules/(?!(jest-)?@react-native|react-native|react-native-elements/*)',],
This got rid of the error above. However, now, I am getting the following error message.
● Test suite failed to run
TypeError: mockModal is not a function
at node_modules/react-native/jest/setup.js:116:12
at Object.<anonymous> (node_modules/react-native/jest/mockModal.js:16:15)
at node_modules/react-native/jest/setup.js:115:28
Environment:
Try using this mock
import .....
jest.mock('@rneui/themed', ()=>({
Button: jest.fn()
}));
describe( ... )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With