React Native Quality Control & Assurance 4 — Questions and Answers
Question 1: Which command runs only tests related to files changed since the last git commit in a Jest watch session?
- jest --only-changed
- jest --watchAll
- jest --watch (press 'o') (Correct answer)
- jest --changed-files
Correct answer: jest --watch (press 'o')
In jest --watch mode, pressing 'o' runs only tests related to changed files, speeding up the feedback loop.
Question 2: What is the purpose of the `testID` prop in React Native components?
- It assigns a CSS class for styling in tests
- It provides a stable identifier for automated testing tools to locate elements (Correct answer)
- It marks a component as a unit test target
- It disables the component during test runs
Correct answer: It provides a stable identifier for automated testing tools to locate elements
The testID prop maps to accessibilityIdentifier (iOS) and resource-id (Android), allowing test frameworks to reliably find elements.
Question 3: In React Native, which linting rule helps prevent accessibility issues that would fail QA audits?
- react-native/no-inline-styles
- eslint-plugin-jsx-a11y rules (Correct answer)
- react-native/sort-styles
- no-unused-vars
Correct answer: eslint-plugin-jsx-a11y rules
eslint-plugin-jsx-a11y enforces accessibility best practices at the code level, catching issues before manual QA.
Question 4: When writing a React Native integration test that calls a real API, what is the best practice to avoid test instability?
- Mock the network layer using msw or jest.mock on fetch/axios (Correct answer)
- Use the production API with a test account
- Disable network calls entirely in jest config
- Use real API calls but retry failed tests automatically
Correct answer: Mock the network layer using msw or jest.mock on fetch/axios
Mocking the network layer with tools like msw (Mock Service Worker) or jest.mock keeps tests fast, deterministic, and offline-capable.
Question 5: What does the `--forceExit` flag do when added to a Jest command?
- Forces all tests to pass regardless of result
- Terminates the Jest process after all tests complete even if async operations are still running (Correct answer)
- Skips cleanup between test suites
- Runs tests without coverage collection
Correct answer: Terminates the Jest process after all tests complete even if async operations are still running
--forceExit ensures Jest exits after tests finish even if open handles (like setInterval or unclosed connections) would otherwise keep the process alive.
Question 6: Which Detox method waits for an element to become visible before interacting with it?
- element(by.id('btn')).waitFor().toBeVisible()
- waitFor(element(by.id('btn'))).toBeVisible().withTimeout(5000) (Correct answer)
- expect(element(by.id('btn'))).eventually.toBeVisible()
- await element(by.id('btn')).visible(5000)
Correct answer: waitFor(element(by.id('btn'))).toBeVisible().withTimeout(5000)
Detox's waitFor(element).toBeVisible().withTimeout(ms) polls until the element is visible or the timeout expires.
Question 7: What is Hermes' role in React Native quality assurance?
- It is a test runner for React Native
- It is a JavaScript engine optimized for React Native that improves startup time and reduces memory usage (Correct answer)
- It provides automated crash reporting
- It is a linting tool for React Native code
Correct answer: It is a JavaScript engine optimized for React Native that improves startup time and reduces memory usage
Hermes is a lightweight JavaScript engine built by Meta that improves app start time, memory footprint, and allows bytecode compilation.
Which command runs only tests related to files changed since the last git commit in a Jest watch session?