React Native Quality Control & Assurance 2 — Questions and Answers
Question 1: Which React Native testing library method is used to simulate a user pressing a button in a component test?
- fireEvent.press(element) (Correct answer)
- simulate('click', element)
- trigger('press', element)
- userEvent.tap(element)
Correct answer: fireEvent.press(element)
fireEvent.press() from @testing-library/react-native simulates a press interaction on a component.
Question 2: What does the `act()` utility do in React Native tests?
- It skips async operations during testing
- It ensures all state updates and effects are processed before assertions (Correct answer)
- It mocks native modules automatically
- It runs tests in a separate thread
Correct answer: It ensures all state updates and effects are processed before assertions
act() ensures that all pending state updates, effects, and re-renders are flushed before you make assertions.
Question 3: In Detox E2E tests, what command is used to find an element by its testID?
- by.text('myId')
- by.id('myId') (Correct answer)
- element.find('myId')
- getByTestId('myId')
Correct answer: by.id('myId')
Detox uses by.id('testID') to locate elements via the testID prop set on React Native components.
Question 4: Which tool is commonly used for visual regression testing in React Native apps?
- Appium screenshot diffing
- Storybook with Chromatic
- Jest snapshot testing of rendered SVGs
- All of the above are valid approaches (Correct answer)
Correct answer: All of the above are valid approaches
Visual regression testing in React Native can use Storybook/Chromatic, Appium screenshots, or Jest snapshots depending on the scope.
Question 5: What is the purpose of `jest.useFakeTimers()` in React Native unit tests?
- To make tests run faster by skipping delays
- To control and advance time-dependent code like setTimeout and setInterval (Correct answer)
- To mock the system clock for date formatting
- To prevent memory leaks from timer callbacks
Correct answer: To control and advance time-dependent code like setTimeout and setInterval
jest.useFakeTimers() replaces native timer functions so tests can control time-based behavior without waiting.
Question 6: Which metric does the React Native Performance Monitor (Perf Monitor) NOT display?
- JS frame rate (FPS)
- UI frame rate (FPS)
- Memory heap size
- Network request latency (Correct answer)
Correct answer: Network request latency
The Perf Monitor shows JS FPS, UI FPS, and RAM usage but does not display network request latency.
Question 7: When mocking a module with Jest in React Native, which syntax correctly auto-mocks all exports?
- jest.mock('./myModule', () => ({}))
- jest.mock('./myModule') (Correct answer)
- jest.spy('./myModule')
- jest.stub('./myModule')
Correct answer: jest.mock('./myModule')
Calling jest.mock('./myModule') without a factory function triggers Jest's automatic mock, replacing all exports with mock functions.
Which React Native testing library method is used to simulate a user pressing a button in a component test?