Jest is a testing framework used to write and run unit tests for React Native apps. It helps check if components and functions work as expected.
Click to reveal answer
beginner
Which command installs Jest and its React Native preset?
You run: npm install --save-dev jest @testing-library/react-native @testing-library/jest-native react-test-renderer to install Jest and tools for React Native testing.
Click to reveal answer
intermediate
What is the purpose of jest.config.js in Jest setup?
The jest.config.js file tells Jest how to run tests, which files to look for, and how to handle React Native specifics.
Click to reveal answer
intermediate
Why do we use react-test-renderer in React Native Jest tests?
It helps create a snapshot of a component’s UI so we can compare it later to catch unexpected changes.
Click to reveal answer
beginner
How do you run Jest tests in a React Native project?
You run npm test or jest in the terminal to start Jest and run all tests.
Click to reveal answer
What file usually contains Jest configuration in a React Native project?
Ametro.config.js
Bjest.config.js
Cbabel.config.js
Dpackage.json
✗ Incorrect
The jest.config.js file is the standard place to put Jest settings.
Which package helps to render React Native components for testing snapshots?
Areact-native-snapshots
Bjest-native
Creact-test-renderer
Dreact-native-testing-library
✗ Incorrect
react-test-renderer creates a serializable output of components for snapshot testing.
What command runs Jest tests in a React Native project?
Anpm install
Bnpm run build
Cnpm start
Dnpm test
✗ Incorrect
npm test runs the test script, which usually runs Jest.
Why do we mock native modules in Jest tests for React Native?
ATo speed up tests and avoid errors from native code
BTo make the app run faster on devices
CTo add animations
DTo improve UI design
✗ Incorrect
Mocking native modules prevents errors and makes tests faster by simulating native behavior.
Which testing library is commonly used with Jest for React Native component testing?
A@testing-library/react-native
BEnzyme
CReact Testing Library
DMocha
✗ Incorrect
@testing-library/react-native provides helpful tools to test React Native components with Jest.
Explain the steps to set up Jest for unit testing in a React Native project.
Think about installation, configuration, writing tests, and running them.
You got /5 concepts.
Describe how snapshot testing works with Jest in React Native.
Focus on rendering, saving, and comparing UI snapshots.
You got /4 concepts.
Practice
(1/5)
1. What is the primary purpose of setting up Jest in a React Native project?
easy
A. To run automated tests and catch bugs early
B. To improve app performance on devices
C. To style components with CSS
D. To deploy the app to app stores
Solution
Step 1: Understand Jest's role
Jest is a testing framework used to run automated tests on code.
Step 2: Identify its main benefit
Running tests helps find bugs early before releasing the app.
Final Answer:
To run automated tests and catch bugs early -> Option A
Quick Check:
Jest purpose = testing and bug catching [OK]
Hint: Jest is for testing code, not styling or deployment [OK]
Common Mistakes:
Confusing Jest with styling tools
Thinking Jest improves app speed
Assuming Jest deploys apps
2. Which of the following is the correct way to import Jest functions in a React Native test file?
easy
A. import { test, expect } from '@testing-library/react-native';
B. No import needed; Jest globals are available automatically
C. const { test, expect } = require('jest');
D. import { test, expect } from 'jest';
Solution
Step 1: Recall Jest globals
Jest provides test and expect as global functions by default.
Step 2: Understand import necessity
Because they are globals, you do not need to import them explicitly.
Final Answer:
No import needed; Jest globals are available automatically -> Option B
Quick Check:
Jest globals = no import needed [OK]
Hint: Jest test and expect are global, no import required [OK]
Common Mistakes:
Trying to import test and expect explicitly
Confusing Jest with other libraries needing imports
Using require instead of relying on globals
3. Given this test code snippet, what will be the test result?
A. toBeTrue() is not a Jest matcher; use toBe(true) instead
B. Missing import of toBeTrue from Jest library
C. Syntax error due to missing semicolon after expect
D. Jest does not support boolean tests
Solution
Step 1: Check Jest matchers for booleans
Jest does not have a matcher called toBeTrue(); it uses toBe(true) instead.
Step 2: Identify cause of syntax error
Using an unknown matcher causes Jest to throw an error.
Final Answer:
toBeTrue() is not a Jest matcher; use toBe(true) instead -> Option A
Quick Check:
Use toBe(true), not toBeTrue() [OK]
Hint: Use toBe(true) for boolean checks, not toBeTrue() [OK]
Common Mistakes:
Trying to import non-existent matchers
Assuming semicolon causes syntax error
Believing Jest can't test booleans
5. You want to test a React Native component that renders a button with text 'Click me'. Which setup is correct to write a Jest test using @testing-library/react-native?