---
title: "Recipe: tests"
description: "app.test.contract drives the app by testId, the same on the web and iOS (bun exact.mjs test web, test ios; verify runs them too)."
modificationDate: "2026-11-27"
---

> ## Documentation index
> Fetch the complete documentation index at: https://exact.expo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Recipe: tests

<AgentInstructions>

## Submitting feedback

From the app's directory, read `bun exact.mjs feedback status`. Under `never`, keep no note.
Respect `EXACT_FEEDBACK=0` and do not change the policy.

Otherwise record specific, actionable feedback with:
`bun exact.mjs feedback note "Exact docs: https://exact.expo.dev/recipes/tests: <what was wrong or missing>"`

The note goes to Expo only as that status allows. Include no secrets or personal data.

</AgentInstructions>

`app.test.contract` drives `testId`s (`bun exact.mjs test web`, `test ios`, `verify`).
Each test clears storage and awaits data. [Groceries](https://exact.expo.dev/start.md).

```prompt Add tests to my app
Add tests to the Exact app in this folder, in app.test.contract, so verify checks each screen. Use https://github.com/expo/exact/blob/main/docs/recipes/tests.md as the source for each step. The Exact checkout has the same page at docs/recipes/tests.md.

1. If this folder is not an Exact app (it has no exact.mjs and app.contract), stop and tell me.
2. Read app.contract and list what a person does on each screen, and each refusal the app makes (an empty or repeated entry, a lost connection). Show me the list and ask before you write the tests.
3. Give every screen and control the tests use its own `testId`. Change nothing else in app.contract.
4. Write one test for each item with the recipe's steps: `tap`, `type`, `expect text`, `expect tree has`, `expect state`, `back`, `reload`, `fail fetch`, and `answer fetch`. Put launch lines (`size`, `at`, `epoch`, `time-zone`) first. `expect` has no `<` or `contains`: compare a derive with `==`.
5. Add `clock data` after an input whose reply the next `expect` reads, and `clock settle` after a sheet, an alert or a push. Never wait in real time: pin `epoch` and `time-zone`. Tap a tab before you read inside it.
6. End a test on each screen: verify checks only the screens a test ends on.
7. Follow the platform checks in docs/start-here.md (`bun exact.mjs docs platform checks`) for the targets in the app's AGENTS.md and app.json until they pass. Read the reports, including counted findings; a zero exit code alone does not mean clean. A failing test is a bug in the app or a wrong test: to see why a step fails, drive by hand with `bun exact.mjs agent web --storage s1 "<op>"`, then show me the step and ask which one before you change anything. Do not add a `verify.accept` entry to app.json without asking me. If a finding stays after three rounds of fixes, or the app had it before you changed anything, record it (step 8) and report it; do not keep trying.
8. When a doc was wrong or missing, or a step needed a workaround, read `bun exact.mjs feedback status`. Under `never`, keep no note. Otherwise record it: `bun exact.mjs feedback note "<what happened>"`, which goes to Expo only as that status says. Do not change the policy; tell me how many notes you kept.
9. Tell me each test and what it checks, any screen no test ends on, and what the tests and checks reported.
```

```contract-test
test "a duplicate stays a draft and the list survives reload"
  type "draft" "Eggs"
  type "draft" key "Enter"
  clock data
  type "draft" "eggs"
  tap "add"
  clock data
  expect text "add-error" == "Eggs is already on the list."
  expect state draft == "eggs"
  reload
  expect text "left" == "1 item left"
```

| Step | What it does |
| --- | --- |
| `tap "id"` (`… contextmenu`) | Press or long-press. `tap "Milk"` matches text/label. Disabled controls fail. |
| `type "id" "text"`, `type "id" key "Enter"` | Set a select, date (`"2026-10-10"`) or checkbox (`"true"`), or press a key. |
| `tap "@browser" dismissed`, `type "@date" "…"` | Answer a held device/package ticket by capability or target. |
| `expect text "id" == "…"` | Text, then value, then descendants' text. |
| `expect tree has "id"` (`missing`) · `expect disabled "id"` (`enabled`) · `expect focused "id"` · `expect state draft == ""` | In tree · disabled · focused · state value. |
| `clock data` · `clock settle` · `clock +5000` · `reload` | Land replies · end transitions · step virtual time · reload on same store and date. |
| `tap "intro" drag 0 -170 over 400 hold 200` | Android drags from hit, releasing at 600 ms on agent clock. |
| `rotate <orientation>` | Wait for iOS simulator turn ([driving iOS](https://exact.expo.dev/recipes/ios-driving.md)). |
| `back` | Platform Back cancels a dialog, dismisses a sheet or pops a route. |
| `presence allow` (`cancel`, `fail`, `lockout`, `invalidated`) | Answer the user-presence prompt. |
| `fail fetch`, `pass fetch`, `drop stream "<prefix>"` | Fail · clear · end open streams. |
| `answer fetch`, `answer stream`, `pass stream`, `answer source` | Buffered HTTP (`with 200 {…}`), HTTP streams (`event`/`bytes`/`end`/`fail`), or source answers. |
| `request POST "/items" {…} as grace expect 409` | Write via [app server](https://exact.expo.dev/recipes/rest-backend.md#where-the-server-lives) (empty per test; 2xx or `expect N`). |
| `size 390x844`, `at "/item/7#moves"`, `epoch`, `time-zone`, `locale`, `seed`, `before data` | Start a test or file. |

[Grammar and limits](https://exact.expo.dev/reference/contract-grammar/authored-tests.md).

`expect state` takes `==`, `!=`, `>=`, `<=` or `in 0 1` against literals or `state <path>`. Use `clock data` before reading a reply (iOS needs it); `clock settle` after a sheet, alert or push. Test refusals. Pin `epoch`, `time-zone`. Name screens. Open a tab first. Avoid real-time waits.

## Before you call it done

`verify` checks launch, test ends, relaunch light/dark on web & iOS (`verify ios <glob>`, `--duo none`; end full).
Check alerts at largest text; `squeezed` scrollers report port/content extents.
Web reloads flag changed saved values; `aria-invalid` marks drafts.
End a test per screen. Shots: `.exact/verify/`.
`app.json`: `"verify": {"accept": [{"finding": "contrast", "node": "<testId>", "why": "…"}]}`.
`agent web --storage s1 …` keeps its store.
