Skip to main content
This page writes the eight tests of the todo-app tutorial with Cucumber. Read about the app and get the project there first. The same tests are also written for Vitest and Jest.

The test files

In todo-tutorial-cucumber, cucumber.mjs loads features/support/quiesco.ts, which registers Quiesco, and the step definitions (Cucumber). The scenarios are in features/list.feature and features/detail.feature, their steps in features/step_definitions/todo.steps.ts; a step reaches the app through this.app. To follow along, empty the three files and add each scenario and its steps as you read them.

Step 1: Give the elements test ids

Tests find elements by their testID. A plain string in a test is a test id: app.tap('add-todo') taps the element with testID="add-todo". The app gives one to every element a test touches or checks: In the code a test id is one prop (src/components/TodoRow.tsx):
Every row has the same ids; a test picks one row by position ({ id: 'todo-title', index: 0 } is the top one) or by its text ({ text: 'Buy milk' }). With the app running, npx quiesco tree prints the element tree with every id, to find the ones an app already has.

Step 2: The first test

Start with what a fresh launch shows:
features/list.feature
features/step_definitions/todo.steps.ts
this.app is the driver for the app under test. The steps read like the user’s actions and checks; the test ids stay in the step definitions. (Given, When, DataTable and SeedTodo are for the steps further down.) Run it on the web:
The first run starts Chromium and opens the app; the test passes in a few seconds. You will run the same file on iOS and Android in step 7.

Step 3: A flow across screens

Now add a todo the way a user does: open the form, type, save, and check the list.
features/list.feature
features/step_definitions/todo.steps.ts
The test has no sleep and no waitFor, although every line depends on something that takes time: the screen transition after tap('add-todo'), the 600 ms save timer, the way back to the list. Quiesco waits for the app to be idle before and after every call — no pending timers, requests, renders or animations (synchronization) — so each line starts where the previous one left the app. Assertions also retry until they hold or time out. expectVisible('new-todo-screen') is not needed for the test to pass, but it makes a failure clearer: if the button stops opening the form, the test fails there and not at type.

Step 4: What the user sees when something is wrong

The form does not save a todo without a title. Check that the error shows and the form stays open, then go back:
features/list.feature
features/step_definitions/todo.steps.ts
goBack() goes back the way the platform does it: the Android back button, the browser’s back, the navigation bar’s back button on iOS. One line covers all three.

Step 5: Start from data with a backdoor

The details screen needs todos in the list. Typing them through the form in every test would work, but it is slow, and a test about deleting a todo would fail whenever the form breaks. A backdoor is a function the app registers for tests only; a test calls it to set up state directly. Declare it once in a file that both the app and the tests compile (src/backdoors.ts):
Register it in src/e2e.ts, the file _layout.tsx loads only in e2e builds, so none of it reaches production:
Now the tests for the details screen start with two todos: The Background runs before every scenario of the feature:
features/detail.feature
features/step_definitions/todo.steps.ts
Because of the declaration (the step file imports src/backdoors.ts), this.app.backdoor('seedTodos', …) is type-checked: a misspelled name or a todo without a title is a TypeScript error in the step. { text: 'Buy milk' } finds the element by what the user reads; expectChecked reads the checkbox’s accessibilityState, the same state a screen reader announces.

Step 6: Every test starts clean

Before every test Quiesco soft-resets the app: it clears storage (AsyncStorage on iOS / Android; localStorage, sessionStorage and IndexedDB on the web), puts navigation back on the first screen and remounts the app. It is much faster than restarting the app. A remount does not clear JavaScript module state, and this app keeps its todos in a module variable. So src/e2e.ts also tells Quiesco how to clear them:
One more test checks it: The Background of features/detail.feature seeds every scenario there, so this one goes at the end of features/list.feature, after the scenario that added a todo:
features/list.feature
Remove the onReset hook and this test fails with the todos of the test before it still on screen. Any state that lives outside React and storage — module variables, caches such as a React Query client, an in-memory database — needs an onReset hook.

Step 7: Run on iOS and Android

The tests do not change. Build the e2e app once per platform, then run the same files:
quiesco test installs the build, starts Metro for the dev client, runs the tests and stops Metro. On iOS and Android tap and type are real touches and keyboard input, not calls into the components: a button covered by the keyboard or another view fails the test (ELEMENT_OBSCURED), as it would stop a user.

When a test fails

Change Then the first todo is "Buy milk" in step 3 to Then the first todo is "Buy bread" and run the tests again. The test fails after the assertion’s timeout with what it expected, what it found and where the app was:
The artifacts/ folder has, per failed test: To run tests from a page in the browser instead — one test at a time, with the run’s progress and a failure’s evidence on the page — install @quiesco/ui and start npx quiesco ui --platform web (test UI).

Next steps

  • Synchronization: what idle means, and what to do with an animation that never stops.
  • API reference: every action and assertion, and the matchers (within, has, regular expressions).
  • Driver pattern: keep test ids out of the tests once a suite grows.