Nts testing patterns
Skill juncoding/nextjs-trpc-prisma-starter/skills/nts-testing-patterns
Claude Code plugin: scaffold and maintain lightweight internal management systems on Next.js + tRPC + Prisma in SPA mode
npx -y skills add juncoding/nextjs-trpc-prisma-starter --skill nts-testing-patternsAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
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.
SKILL.md
4.6 KB, as published. Nobody here has run it
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.config.js pattern <rootDir>/src/**/*.spec.ts picks them up.
What to actually test
Always test in services
- Permission denial — caller without scope throws.
- Input validation — bad input throws.
- The happy path — correct DB calls, correct return shape.
- Important branches — state-machine transitions, conditional cascades.
- Tx rollback — failing audit rolls back the mutation.
Test sparingly in routers
- "Public procedure is public" / "protected procedure rejects unauthenticated" — one of each, for sanity.
- That input passes through unchanged.
Do NOT re-test the service from the router level. That's duplication. The router is a pipe; verifying the pipe doesn't kink is enough.
Test minimally in MCP tools and route handlers
If the tool/handler is genuinely a thin wrapper around the service, one test that confirms it calls the service is enough. The service tests cover the rest.
Test e2e for golden flows only
- Login → land on dashboard.
- Create a record via the UI, verify it appears in the list.
- One full per-domain happy path (e.g. quote → award → SO created).
Don't try to e2e-test every form validation. That's what the service + router tests are for.
What NOT to mock
- Prisma in service tests: mocking the entire Prisma client is brittle and provides false confidence. Prefer either:
- Real DB via Testcontainers (slower but real) for the canary integration test per module.
- A targeted mock of
db.<table>.<method>for branch-coverage unit tests.
requireSession/requirePermission: mock withjest.mock(...)— they're auth boundary, not what you're testing.- External services (Resend, S3, Gotenberg): always mock. Don't hit live services in tests.
What's worth automating vs. manual
Automate:
- Anything tied to a permission grant (so a role-permission change can't silently break access).
- State-machine transitions.
- Currency/unit/timezone conversions.
- Anything that has bitten you once.
Manual:
- Visual layouts.
- New UI components on first review.
- Anything where the test-writing time exceeds the bug-finding return.
Running tests
pnpm test # full suite, headless
pnpm test:watch # watch mode for a focused module
pnpm test customer.service # filter
The full suite should stay green at every commit. If a test goes red, fix it or delete it — don't let red tests accumulate.
Gives 0 of the 12 instructions most e2e browser skills give
Counted across 407 of the 410 authors here whose files we hold, read 2026-08-06
- use page object model patternin 35 of 407, across 25 files
- Snapshot to get element refsin 24 of 407, across 14 files
- keep tests independentin 23 of 407, across 18 files
- Interact using refs from the latest snapshotin 23 of 407, across 11 files
- clean up test data after each testin 21 of 407, across 15 files
- test user behavior not implementationin 20 of 407, across 14 files
- quarantine flaky tests explicitlyin 19 of 407, across 10 files
- wait for specific network conditionsin 18 of 407, across 8 files
- re-snapshot after navigation or dom changesin 17 of 407, across 10 files
- Detect running dev servers before writing test codein 17 of 407, across 7 files
- use web-first assertionsin 17 of 407, across 14 files
- capture screenshots or videos on test failurein 17 of 407, across 14 files
Said here and by no other author read
- colocate spec files next to source files
- focus testing effort on service layer
- test permission denial and input validation in services
- test state machine transitions and rollbacks
- avoid re-testing service logic in routers
- restrict end-to-end tests to critical user flows
Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once.