Recall & Review
beginner
What does mocking native modules mean in React Native testing?
Mocking native modules means creating fake versions of native code components so tests can run without relying on actual device features or native implementations.
Click to reveal answer
beginner
Why do we mock native modules in React Native tests?
We mock native modules to isolate JavaScript code from native code, making tests faster, more reliable, and easier to run on any environment without device dependencies.
Click to reveal answer
beginner
Which Jest function is commonly used to mock native modules in React Native?
The Jest function jest.mock() is used to replace native modules with mock implementations during testing.
Click to reveal answer
intermediate
How do you mock the React Native native module 'AsyncStorage' in a test?
You can mock AsyncStorage by calling jest.mock('@react-native-async-storage/async-storage', () => mockImplementation) where mockImplementation fakes AsyncStorage methods like getItem and setItem.
Click to reveal answer
intermediate
What is a key benefit of mocking native modules when running tests on a CI/CD pipeline?
Mocking native modules allows tests to run in environments without real devices or emulators, ensuring tests pass consistently and quickly in automated pipelines.
Click to reveal answer
What is the main purpose of mocking native modules in React Native?
✗ Incorrect
Mocking native modules simulates native features so tests can run without needing actual devices.
Which Jest method is used to replace a native module with a mock?
✗ Incorrect
jest.mock() replaces modules with mocks during testing.
If a native module is not mocked, what can happen during tests?
✗ Incorrect
Without mocking, tests can fail because native code is unavailable in the test environment.
What is a common way to mock AsyncStorage in React Native tests?
✗ Incorrect
jest.mock() with a fake AsyncStorage lets tests run without real storage.
Why is mocking native modules important for CI/CD pipelines?
✗ Incorrect
Mocking lets tests run in automated environments without device dependencies.
Explain how and why you would mock a native module in a React Native test.
Think about replacing native code with fake code during tests.
You got /4 concepts.
Describe the benefits of mocking native modules when running tests in a continuous integration system.
Consider what happens when no real device is available.
You got /4 concepts.