---
title: "Recipe: testing against a Snapback backend"
description: "A Snapback app needs its backend running before test web."
modificationDate: "2026-11-12"
---

> ## 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: testing against a Snapback backend

<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/snapback-tests: <what was wrong or missing>"`

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

</AgentInstructions>

A Snapback app needs its backend running before `test web`: the runner checks
loopback origins in `app.ts`’s `net.fetch` grants and refuses a Snapback run if
none listens. Start `snapback4 dev` on that origin’s port, seeded if needed;
`EXACT_PORT` sets the page’s port and never moves the backend.

Each test opens empty app storage; backend rows survive tests and runs unless
`fresh` at the file’s top (or leading a test) empties `snapback4 dev` before each
test. This uses `POST /dev/reset` (Snapback4 **0.4.33**, `dev` only; a
password-only app's `dev` opens it only with `--unsafe-dev-doors`).
`fresh "seed.json"` then seeds it with `[{"table": …, "row": {…}}]`, from a path
relative to the test file. A server lacking reset fails the test.
Each seed row includes a stable 26-character Crockford base32 `id` (digits
and capital letters except I, L, O and U); the scaffold supplies these ids.
Tables with `insert <- deny` (or no `insert` rule) are commonly role rosters provisioned outside the
app: bare `fresh` removes them too, so privileged operations will refuse.
Use `fresh "seed.json"` and seed those roster rows for each test. A `--snapback`
scaffold writes sample roster rows (or copies the backend's `seed.json`);
review their persona, role and field values before using them.
The runner warns when the drive epoch differs from the backend clock by more
than a day, including an explicitly chosen epoch. `epoch now` follows real time;
an intentional clock test must arrange both clocks.

Server ids are unique, not ordered. Sort by time; tests can reach rows by text
or position (`for t, i in tasks key=t.id`, ``testId=`task-${i}` ``).

Wiring the backend: [a Snapback backend (shared server data)](https://exact.expo.dev/recipes/snapback.md).

A test that deliberately refuses a request asserts it after settling data:

```prompt Test my app against its Snapback backend
Add tests to the Exact app in this folder that run against its Snapback backend. Use https://github.com/expo/exact/blob/main/docs/recipes/snapback-tests.md as the source for each step. The Exact checkout has the same page at docs/recipes/snapback-tests.md.

1. If this folder is not an Exact app (it has no exact.mjs and app.contract), or app.ts grants no loopback `net.fetch` origin for a Snapback backend, stop and tell me: wire it first with docs/recipes/snapback.md.
2. Start `snapback4 dev` on that origin's port, as `bun exact.mjs snapback` names it, before the checks run: the runner refuses a Snapback run when none listens. `EXACT_PORT` moves the page's port, never the backend's.
3. Backend rows survive tests and runs. For tests that need an empty backend, put `fresh` at the top of app.test.contract, or `fresh "seed.json"` to seed it. This needs Snapback4 0.4.33. A password-only app's `dev` opens reset only with `--unsafe-dev-doors`: ask me before you use it.
4. If a table allows no `insert` (a role roster), seed its rows in seed.json for each test. Each seed row needs a stable 26-character Crockford base32 `id`. Show me the sample roster rows (persona, role and fields) and ask before you use them.
5. Server ids are unique, not ordered: reach rows by text or by position (``testId=`task-${i}` ``), never by id order. Use `epoch now` unless a test arranges both clocks.
6. For each write the server refuses, add a test: `clock data`, then `expect refusal "<mutation slot>"`, then expect the code or message the app shows.
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. Fix the app, not the test. 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, the command that starts the backend, the seed you used, and what the tests and checks reported.
```

```contract-test
test "the full slot refuses a write"
  tap "send"
  clock data
  expect refusal "posted"
  expect text "error" == "SLOT_FULL"
```

`posted` is the Contract mutation slot. Each assertion consumes one
observed refusal from that slot; an unexpected or extra refusal remains a wiring
problem. Assert the failure's rendered code or message too. A refused mutation
keeps its prior successful reply and runs no `then`, so matching the slot alone
does not show the latest failure.
