← ClaudeAtlas

nts-testing-patternslisted

Test-writing patterns for projects scaffolded with nextjs-trpc-prisma-starter. Use whenever the user is writing or reviewing tests in such a project, asks 'how do I test X', wants to add test coverage for a new module, or needs to debug a failing test. Covers service-layer unit tests (the high-value layer), tRPC procedure tests via createCaller (typed, no HTTP), MCP tool tests, route handler tests, and Playwright e2e. Each section explains WHAT to test at that layer and HOW so test effort lands where it pays off.
juncoding/nextjs-trpc-prisma-starter · ★ 0 · Testing & QA · score 70
Install: claude install-skill juncoding/nextjs-trpc-prisma-starter
# Testing patterns ## The testing pyramid for this stack ``` ▲ ▲▲▲ Playwright e2e (a few smoke flows) ▲▲▲▲▲▲▲ tRPC procedure tests via createCaller ▲▲▲▲▲▲▲▲▲▲▲ Service-layer tests ← MOST VALUE LIVES HERE ▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲ Schema parsing tests (Zod, cheap, run lots) ``` The high-value layer is the **service**. Test it well. The other layers are thin enough that "did I wire it correctly" tests are cheap and sufficient. ## Index | Testing this | Read this | |---|---| | A service method | `references/service-tests.md` | | A tRPC procedure | `references/trpc-caller-tests.md` | | An MCP tool | `references/service-tests.md` (same as a service — MCP tools are thin wrappers) | | A route handler (REST, webhook) | `references/service-tests.md` + call the route fn directly | | A full user flow | `references/e2e-playwright.md` | ## Where tests live Colocate next to the code they test: ``` src/server/modules/customer/ ├── customer.service.ts ├── customer.service.spec.ts ← unit tests here ├── customer.schema.ts └── customer.schema.spec.ts ← Zod parsing tests src/server/api/routers/ ├── customer.ts └── customer.spec.ts ← createCaller tests src/app/api/v1/orders/[id]/ ├── route.ts └── route.spec.ts ← route handler tests tests/e2e/ └── customer-flow.spec.ts ← Playwright ``` Tests next to code makes them findable when refactoring. The `jest.