Detox is a gray-box end-to-end testing framework for React Native that instruments the app to synchronize with async operations automatically. Unlike black-box tools, Detox eliminates flaky sleep-based waits by monitoring network requests, timers, and animations.
0 / 5 completed
1 / 5
What makes Detox a 'gray-box' testing framework compared to black-box testing tools like Appium?
Detox is called gray-box because it instruments the app and has visibility into its internal state. Detox automatically waits for async operations (network requests, timers, animations) to complete before running assertions, eliminating the need for sleep() calls that plague black-box tools.
2 / 5
A developer writes await element(by.id('loginButton')).tap() in a Detox test. What does by.id() match against?
by.id() in Detox matches the testID prop on React Native components. Setting testID="loginButton" on a <TouchableOpacity> makes it selectable in tests. This is the preferred selector because it's stable across UI refactors that might change labels or positions.
3 / 5
What is the purpose of Detox's device.reloadReactNative() method in tests?
device.reloadReactNative() reloads the JavaScript bundle without reinstalling the native app. This is much faster than device.launchApp() and is useful in beforeEach hooks to reset app state between tests while keeping the same native shell running.
4 / 5
A Detox test fails intermittently because a network request takes longer than usual. What is the proper Detox way to handle this?
waitFor().withTimeout() is Detox's declarative way to handle asynchronous UI changes. Instead of fixed sleeps, await waitFor(element(by.id('result'))).toBeVisible().withTimeout(10000) polls until the element is visible or the timeout expires, making tests resilient to timing variation.
5 / 5
Which Detox configuration setting allows running tests on a specific iOS simulator model?
The device.type field in Detox configuration (in package.json or .detoxrc.js) specifies the device type. For iOS, set type: 'ios.simulator' and device: { type: 'iPhone 15' } under the device configuration to target a specific simulator model.