nts-testing-patternslisted
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.