Bird
Raised Fist0
React Nativemobile~20 mins

Detox for E2E testing in React Native - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Detox Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate
2:00remaining
What does this Detox test check?
Given this Detox test code, what UI behavior is being verified?
React Native
describe('Login screen', () => {
  beforeEach(async () => {
    await device.reloadReactNative();
  });

  it('should show error on empty login', async () => {
    await element(by.id('loginButton')).tap();
    await expect(element(by.text('Please enter username'))).toBeVisible();
  });
});
AChecks that app crashes on empty login
BChecks that login button is disabled initially
CChecks that username input accepts text
DChecks that tapping login without username shows an error message
Attempts:
2 left
💡 Hint
Look at what element is tapped and what text is expected to be visible.
❓ lifecycle
intermediate
1:30remaining
What does device.reloadReactNative() do in Detox?
In Detox tests, what is the purpose of calling device.reloadReactNative() before each test?
AIt restarts the React Native app to a fresh state before each test
BIt reloads only the JavaScript bundle without restarting the app
CIt clears the app cache but keeps the current screen
DIt resets the device to factory settings
Attempts:
2 left
💡 Hint
Think about why tests need a clean start.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in this Detox test snippet
What is the syntax error in this Detox test code?
React Native
it('should login successfully', async () => {
  await element(by.id('usernameInput')).typeText('user');
  await element(by.id('passwordInput')).typeText('pass');
  element(by.id('loginButton')).tap()
  await expect(element(by.id('welcomeMessage'))).toBeVisible();
});
AMissing await before element(by.id('loginButton')).tap()
BMissing semicolon after tap() call
CMissing comma between arguments in typeText()
DMissing closing parenthesis in expect()
Attempts:
2 left
💡 Hint
Check async calls and awaits carefully.
🔧 Debug
advanced
2:30remaining
Why does this Detox test fail with timeout?
This Detox test fails with a timeout error on the last expect statement. Why?
React Native
it('shows welcome after login', async () => {
  await element(by.id('usernameInput')).typeText('user');
  await element(by.id('passwordInput')).typeText('pass');
  await element(by.id('loginButton')).tap();
  await expect(element(by.id('welcomeMessage'))).toBeVisible();
});
AThe tap() call is missing await causing race condition
BThe test is missing a waitFor() to wait for welcomeMessage to appear
CThe welcomeMessage element is not visible because login failed silently
DThe usernameInput and passwordInput IDs are incorrect
Attempts:
2 left
💡 Hint
Consider what happens if login does not succeed.
🧠 Conceptual
expert
3:00remaining
Why use Detox for React Native E2E testing instead of Jest alone?
Which reason best explains why Detox is preferred for end-to-end testing in React Native apps over Jest unit tests?
ADetox is faster than Jest for running unit tests
BDetox runs tests on real devices or emulators simulating user interactions, while Jest tests only logic in isolation
CJest cannot run any tests on React Native apps
DDetox automatically fixes UI bugs during tests
Attempts:
2 left
💡 Hint
Think about what E2E testing means compared to unit testing.

Practice

(1/5)
1. What is the main purpose of Detox in React Native app development?
easy
A. To build the app's backend API
B. To style the app components
C. To automate user actions and test the app end-to-end
D. To manage app state

Solution

  1. Step 1: Understand Detox's role

    Detox is a testing tool that automates user interactions to check if the app works correctly from start to finish.
  2. Step 2: Compare options

    Options A, B, and C relate to backend, styling, and state management, which are not Detox's purpose.
  3. Final Answer:

    To automate user actions and test the app end-to-end -> Option C
  4. Quick Check:

    Detox purpose = automate user actions [OK]
Hint: Detox tests the whole app flow by simulating user actions [OK]
Common Mistakes:
  • Confusing Detox with styling or state tools
  • Thinking Detox builds backend APIs
  • Assuming Detox only tests small parts
2. Which Detox function is used to group related tests together?
easy
A. describe()
B. it()
C. expect()
D. beforeEach()

Solution

  1. Step 1: Identify grouping function

    The describe() function groups related tests into a suite for better organization.
  2. Step 2: Understand other functions

    it() defines individual tests, expect() makes assertions, and beforeEach() runs setup code before tests.
  3. Final Answer:

    describe() -> Option A
  4. Quick Check:

    Group tests = describe() [OK]
Hint: Use describe() to group tests, it() for each test [OK]
Common Mistakes:
  • Using it() to group tests instead of describe()
  • Confusing expect() with grouping
  • Thinking beforeEach() groups tests
3. Given this Detox test snippet, what will happen?
await element(by.id('loginButton')).tap();
await expect(element(by.id('welcomeMessage'))).toBeVisible();
medium
A. The test taps the welcome message and checks if login button is visible
B. The test taps the login button and checks if the welcome message is visible
C. The test fails because tap() is called on a non-existent element
D. The test only checks visibility without any tap action

Solution

  1. Step 1: Analyze the tap action

    The code taps the element with testID 'loginButton', simulating a user pressing it.
  2. Step 2: Analyze the expectation

    It then checks if the element with testID 'welcomeMessage' is visible on screen.
  3. Final Answer:

    The test taps the login button and checks if the welcome message is visible -> Option B
  4. Quick Check:

    tap loginButton + expect welcomeMessage visible = B [OK]
Hint: Read code line by line: tap first, then check visibility [OK]
Common Mistakes:
  • Mixing up which element is tapped
  • Assuming tap() fails without checking element existence
  • Ignoring the order of actions
4. You wrote this Detox test but it fails with "Cannot find element by id 'submitBtn'" error. What is the likely cause?
await element(by.id('submitBtn')).tap();
medium
A. You forgot to import Detox
B. The tap() function is misspelled
C. Detox does not support by.id selector
D. The app does not have a UI element with testID 'submitBtn'

Solution

  1. Step 1: Understand the error message

    The error says Detox cannot find an element with testID 'submitBtn', meaning it does not exist or is not rendered.
  2. Step 2: Check other options

    tap() spelling is correct, Detox supports by.id, and import errors cause different failures.
  3. Final Answer:

    The app does not have a UI element with testID 'submitBtn' -> Option D
  4. Quick Check:

    Element not found = missing testID in app [OK]
Hint: Check if testID matches exactly in app code [OK]
Common Mistakes:
  • Assuming tap() is wrong
  • Thinking Detox lacks by.id support
  • Ignoring testID spelling or missing assignment
5. You want to write a Detox test that waits for a loading spinner to disappear before tapping a button with testID 'continueBtn'. Which code snippet correctly does this?
hard
A. await waitFor(element(by.id('spinner'))).toBeNotVisible().withTimeout(5000); await element(by.id('continueBtn')).tap();
B. await element(by.id('spinner')).tap(); await element(by.id('continueBtn')).tap();
C. await expect(element(by.id('spinner'))).toBeVisible(); await element(by.id('continueBtn')).tap();
D. await element(by.id('continueBtn')).tap(); await waitFor(element(by.id('spinner'))).toBeNotVisible();

Solution

  1. Step 1: Wait for spinner to disappear

    Use waitFor(...).toBeNotVisible() with a timeout to pause until spinner hides.
  2. Step 2: Tap the continue button after spinner disappears

    After waiting, tap the button safely knowing the UI is ready.
  3. Final Answer:

    await waitFor(element(by.id('spinner'))).toBeNotVisible().withTimeout(5000); await element(by.id('continueBtn')).tap(); -> Option A
  4. Quick Check:

    Wait for spinner gone, then tap button = C [OK]
Hint: Wait for element to hide before tapping next [OK]
Common Mistakes:
  • Tapping spinner instead of waiting
  • Tapping button before spinner disappears
  • Checking spinner visible instead of not visible
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard