Before Mrs. Rini's new branch opens, there's a trial run. Checking each washing machine on its own is like a unit test. Having an employee pretend to be a customer, from walking in with laundry to receiving the receipt, is an E2E (end-to-end) test. In an app, that "employee" is a robot that uses the real app on a simulator or emulator exactly like a user: it opens the app, taps, then reads the screen.
The test pyramid for this app
| Layer | What's tested | Tool | How many |
|---|---|---|---|
| Unit | plain functions: formatPrice(14) becomes '$14' |
Jest | many |
| Component | OrderRow shows #13 and passes on a tap |
Jest + React Native Testing Library | quite a few |
| E2E | open the app → see order #13 → open its detail | Maestro or Detox | few, key flows only |
Unit and component tests run in seconds on a laptop. E2E tests need an app build and a simulator, so they're slow and more fragile: use them for flows whose breakage costs money (login, seeing an order, requesting a pickup). Versions as of 11 October 2026: jest-expo 57.0.5 (on Jest 29.7), @testing-library/react-native 14.1.0, Maestro CLI 2.11.0, Detox 20.51.4.
Component tests: Jest and React Native Testing Library
npx expo install jest-expo jest @types/jest --dev
npx expo install @testing-library/react-native --dev
npm install -D [email protected] # RNTL 14 needs test-renderer, version 1.2 for React 19.2
In package.json: "jest": { "preset": "jest-expo" } and the script "test": "jest --watchAll". OrderRow moved to src/components/OrderRow.tsx and got a testID:
// src/components/__tests__/OrderRow.test.tsx
import { render, screen, userEvent } from '@testing-library/react-native';
import { OrderRow } from '@/components/OrderRow';
import type { Order } from '@/data/orders';
const order13: Order = { id: '13', name: 'Wulan', kg: 2, status: 'Ironing' };
test('OrderRow shows order #13 and sends its id when tapped', async () => {
const onPress = jest.fn();
const user = userEvent.setup();
await render(<OrderRow order={order13} onPress={onPress} />);
expect(screen.getByText('#13 Wulan')).toBeOnTheScreen();
expect(screen.getByText('2 kg · $14')).toBeOnTheScreen();
expect(screen.getByText('Ironing')).toBeOnTheScreen();
await user.press(screen.getByTestId('order-13'));
expect(onPress).toHaveBeenCalledWith('13');
});
Run in this project:
$ npx jest src/components/__tests__/OrderRow.test.tsx
PASS src/components/__tests__/OrderRow.test.tsx
✓ OrderRow shows order #13 and sends its id when tapped (460 ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
- In RNTL 14,
renderandfireEventare async: writeawait render(...). Examples withoutawaitcome from version 13. getByTextjoins the text pieces inside one<Text>, so#{order.id} {order.name}reads as'#13 Wulan'.userEvent.pressruns the sequence of touch events a real finger makes. With a wrongtestID, the result isUnable to find an element with testID: order-12, with the component tree printed below it.
testID: a handle for the robot
<Pressable testID={`order-${order.id}`} onPress={() => onPress(order.id)}>
testID becomes the accessibility identifier on iOS and the view's identifier on Android. Jest, Maestro (id:) and Detox (by.id) all look it up there. Finding by text works too, but it breaks easily: translate or slightly change the text and the test fails.
Maestro: a flow in YAML
Maestro is a separate CLI (it needs Java 17+), installed with curl -fsSL "https://get.maestro.mobile.dev" | bash. The app doesn't change at all:
# .maestro/open-order-13.yaml
appId: com.rinislaundry.app
---
- launchApp:
clearState: true
- assertVisible:
id: "order-13"
- tapOn:
id: "order-13"
- assertVisible: "Wulan: Ironing"
- Run it with
maestro test .maestro/open-order-13.yaml, with a simulator or emulator already running and the app installed (a development build, oreas buildwith"ios": { "simulator": true }and"android": { "buildType": "apk" }). assertVisibledoesn't fail at once: Maestro retries for up to 7 seconds. For anything longer,extendedWaitUntil.- In Expo Go,
launchAppwith your ownappIdcan't be used. UseopenLinkto theexp://address instead. - Expo's docs recommend Maestro for E2E on EAS Workflows.
Detox: grey-box and synchronisation
Guess first: the order list comes from the server in 2 seconds. Your Detox test runs await expect(element(by.id('order-13'))).toBeVisible() right after the app opens, with no sleep. Pass or fail?
Detox (from Wix) writes tests in JavaScript with the Jest 29 runner, and its library is built into the app. Because it "sees inside" the app, Detox is called grey-box:
// e2e/order.test.js
describe('My orders', () => {
beforeAll(async () => {
await device.launchApp({ newInstance: true });
});
it('opens the detail of order #13', async () => {
await expect(element(by.id('order-13'))).toBeVisible();
await element(by.id('order-13')).tap();
await expect(element(by.text('Wulan: Ironing'))).toBeVisible();
});
});
- Install:
npm install detox "jest@^29" --save-dev, thennpx detox initcreates.detoxrc.js,e2e/jest.config.jsande2e/starter.test.js. In an Expo project, the native folders come from prebuild and@config-plugins/detox(11.0.0) prepares them. That plugin's README version table only goes up to SDK 53, so budget time for matching versions. jest@^29fits SDK 57, because jest-expo 57 is built on Jest 29. On SDK 58, jest-expo 58.0.14 uses Jest 30 (babel-jest^30.0.0), so install"jest@^30"to avoid mixing two major versions. Detox 20.51.4 accepts Jest 29 or 30 (npm, 15 November 2026).npx detox build --configuration ios.sim.debug, thennpx detox test --configuration ios.sim.debug.- Automatic synchronisation: before every action and check, Detox waits for the app to be idle: network requests, timers, animations and the JavaScript thread. So a list arriving in 2 seconds is waited for on its own, and
toBeVisible()passes withoutsleep. - For things outside synchronisation (say, data over a WebSocket), use
await waitFor(element(by.id('order-13'))).toBeVisible().withTimeout(5000). - An animation that loops forever keeps the app from ever being idle, and the test waits until it times out. Turn the animation off in the test build, or
await device.disableSynchronization()for that part only. - When a
testIDisn't found, Detox on iOS reportsNo elements found for “MATCHER(id == “order-13”)”.
| Maestro | Detox | |
|---|---|---|
| Test language | YAML | JavaScript (Jest) |
| Waiting | retries each check for up to 7 seconds | waits for the app to be idle (grey-box) |
| Changes to the app | none | the Detox library is built in, plus a config plugin on Expo |
| Expo Go | through openLink |
no, it needs its own build |
Tests that sometimes pass, sometimes fail (flaky)
- Server data changes. Mrs. Rini moves #13 to "Ready for pickup", and
assertVisible: "Wulan: Ironing"fails. Use a staging server with fixed data, or a fake API. - A fixed
sleep. Sometimes too short, sometimes wasted time. Use Detox's synchronisation,waitFor, orextendedWaitUntil. - Permission dialogs. The notification dialog covers the screen. On iOS, Detox can grant permission when it launches the app:
device.launchApp({ permissions: { notifications: 'YES' } }). - Leftovers from the previous test. A login or a cache left behind. Start clean with
clearState: true(Maestro) ornewInstance/delete(Detox). - Running all of this automatically on every pull request is covered in the next lesson, mobile CI/CD.
⚠️ Tests that are slow, brittle or read the screen too early
- Forgetting
awaitin RNTL 14.renderandfireEventare async now. Withoutawait, the test reads the screen before it's ready. - No
testID. The test leans on text that can change. Give atestIDto the elements you tap and check. - Adding
sleepto patch a test. Find the real thing to wait for: Detox's synchronisation,waitFor, orextendedWaitUntil. - Testing everything through E2E. Slow and fragile. Logic in unit tests, rendering in component tests, E2E for key flows only.
TL;DR: Mrs. Rini's test pyramid: many unit and component tests with Jest (jest-expo 57.0.5, Jest 29.7) and React Native Testing Library 14.1.0 (await render, userEvent.press, getByTestId), and a few E2E tests for the flow "open the app → order #13 → detail". testID (order-13 for order #13) is the handle for every tool. Maestro (CLI 2.11.0) writes flows in YAML (launchApp, assertVisible, tapOn with id), doesn't change the app, and retries each check for up to 7 seconds; Expo recommends it for EAS Workflows. Detox (20.51.4) is an end-to-end testing framework for React Native that runs tests on a real simulator or emulator, written in JavaScript, with grey-box automatic synchronisation: it waits for network, timers, animations and the JavaScript thread on its own, and for special cases uses waitFor().toBeVisible().withTimeout(). Tests turn flaky because of changing data, sleep, permission dialogs and leftover state: use fixed data, wait for the right thing, and start clean.
⚡ The test pyramid
Meaning: Many unit and component tests with Jest and React Native Testing Library, which run in seconds on a laptop. Few E2E tests, because they need a build and a simulator: enough for flows whose breakage costs money, such as "open the app → order #13 → detail".
⚡ testID, a handle for the robot
Write:
<Pressable testID={`order-${order.id}`} onPress={() => onPress(order.id)}>
Meaning: Jest, Maestro (id:) and Detox (by.id) all look up order-13 here. Finding by text works too, but it breaks easily when the text changes slightly.
⚡ Detox waits on its own
Guess first: the order list comes from the server in 2 seconds. Your Detox test runs toBeVisible() for order-13 right away, with no sleep. Pass or fail?
Pass. Before every action and check, Detox waits for the app to be idle: network requests, timers, animations and the JavaScript thread.
Meaning: That's grey-box automatic synchronisation. For things outside synchronisation, such as data over a WebSocket, use waitFor(...).toBeVisible().withTimeout(5000), not sleep.