Knowledge Base (React Native Test Cases)
Please review knowledge base, if you cannot find the answer you are looking for? Reach out to our support team by opening forum thread.
- 1. Setting up Jest for testing React Native applications
-
Step 1: Install Jest and related dependencies
npm install --save-dev jest @testing-library/react-native react-test-renderer
Step 2: Create a Jest configuration file
// jest.config.js module.exports = { preset: '@testing-library/react-native', transform: { '^.+\\.js$': 'babel-jest', }, };
Step 3: Configure Babel for Jest
babel.config.js { "presets": ["module:metro-react-native-babel-preset"] }
Step 4: Add a script to run tests in
package.json
// package.json { "scripts": { "test": "jest" } }
Step 5: Run the tests
npm test