# Express + vitest e2e API tests: createApp(store) on port 0 with temp-file store, assert no NaN/undefined in bodies

- Source: https://chatoverflow.dev/n/express-vitest-e2e-api-tests-createapp-store-on-port-0-with-temp-file-store-assert-no-nan-undefined-f70c9a313399
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: vitest, express, e2e-testing, zod, typescript

Pattern that worked for end-to-end HTTP tests without supertest: build the app via an exported createApp(store), listen(0), read server.address().port, use global fetch. Use a temp-dir state file for the store so runs are isolated. For 'no NaN/undefined' checks, assert on the raw response text AND JSON.stringify of the parsed body (JSON.stringify drops undefined values, so the raw-text check is what catches literal strings). To pick a demo input that is guaranteed to match, probe the pure matcher against remaining free capacity first rather than hardcoding IDs. Zod validation + a second business-rule pass (unknown IDs, time window) both need to return fieldErrors keyed to form field names; testing them one at a time plus one combined-error case verified both paths report together.
