typescript-testing-backend
Skill17 starsChanged 21 days agoMITView on GitHub
Use when writing or reviewing TypeScript backend tests — Jest unit tests for services/controllers (mocked Prisma) or Supertest integration tests against a real isolated PostgreSQL test database. Triggers on edits to `*.service.test.ts`, `*.controller.test.ts`, `*.integration.test.ts`, service/controller/API test files (`.ts`, not `.tsx`) under `**/__tests__/`, or mentions of "backend test", "service test", "API test", "database test".
In this repository38 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- adversarial-claims-reviewerSkill
- autoresearchSkill
- browser-testing-with-devtoolsSkill
- codebase-cost-estimatorSkill
- code-review-and-qualitySkill
- content-opsSkill
- content-pipelineSkill
- conversion-opsSkill
- data-model-documentationSkill
- data-model-verificationSkill
- deployment-pipelinesSkill
- findings-ledgerSkill
- game-balancerSkill
- game-systems-designerSkill
- godot-engineerSkill
- growth-engineSkill
- iap-managerSkill
- library-investigatorSkill
- marketing-shaperSkill
- memory-extractionSkill
- outbound-engineSkill
- phaser-engineerSkill
- planning-and-task-breakdownSkill
- prompt-shaperSkill
- release-managerSkill
- revenue-intelligenceSkill
- rust-engineerSkill
- security-engineeringSkill
- securitySkill
- seo-opsSkill
- session-stateSkill
- skill-library-reviewSkill
- telemetrySkill
- typescript-analyticsSkill
- typescript-data-engineeringSkill
- typescript-testing-frontendSkill
- web3-smart-contract-engineeringSkill
The file
Files
TypeScript Testing — Backend
You are operating as a backend test engineer. Mock at the module edge for units, hit a real Postgres for integration, and never assert on internal call shapes.
Reference stack: Jest 29 with @swc/jest, Supertest for HTTP, a custom TestServer helper that simulates Next.js route handlers, and a TestDatabase helper that provisions isolated PostgreSQL instances per run with migrations + seed. Tests live co-located in __tests__/ folders.
Unit tests mock the Prisma client at the module boundary; integration tests use the real DB plus an auth-state helper for authenticated request flows.
Universal Rules
- Use Jest —
jest.mock()/jest.fn(), nevervi.*. - Co-locate tests in
__tests__/next to the source. - Mock at the module boundary — not internal functions.
- Literal expected values —
expect(total).toBe(70), never expressions. - Every
it()asserts observable behavior with at least oneexpect(). beforeEachcleanup, scoped to test-created records — never truncate seed data.- Clear auth/state helpers between tests so authenticated flows don't bleed across cases.
- Never
test.skip()— fix or delete. - Real DB for integration tests, mocked Prisma for unit tests.
- Internal utils stay real — only mock external boundaries.
References
- references/framework-and-structure.md — Jest config, test scripts, directory layout, file naming conventions, coverage
- references/unit-testing.md — service unit tests with mocked Prisma, controller unit tests with injected service mocks
- references/integration-testing.md — shared setup, full Supertest example,
TestServerpattern,authTestHelpersAPI - references/database-testing.md —
setupTestDatabase, isolated DBs, cleanup rules, accessing seeded data - references/mock-policy-and-quality.md — mock scope table, quality criteria, test failure triage
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

