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

The test files

In todo-tutorial-jest, jest.config.cjs uses the @quiesco/jest preset and runs e2e/**/*.test.js (Jest). The tests are in e2e/list.test.js and e2e/detail.test.js: plain JavaScript, with the app in the global quiesco.app. To follow along, empty both files and add each test as you read it.

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:
e2e/list.test.js
quiesco.app is the driver for the app under test. quiesco is a global, like Jest’s own test. 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.
e2e/list.test.js
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:
e2e/list.test.js
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

Up to Quiesco 0.13.4, quiesco.app.backdoor() under Jest rejects any object argument as “not JSON” (#115). Until the fix is released, the tests in this step fail with NOT_SERIALIZABLE.
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:
e2e/detail.test.js
The test files are plain JavaScript, so nothing checks the backdoor’s name and arguments before the run: a wrong one fails the test when it calls the backdoor. { 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:
e2e/detail.test.js
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 the expected title in step 3 to '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.