testing-guide
Skill17 starsChanged 9 months agoMITView on GitHub
Test writing patterns, mocking strategies, and test data templates for Jest unit and integration tests. Use when writing new tests or need guidance on mocking repositories.
- Reads credentials
5 other projects use a version of this.
Adopted by
Most recently taken up by
- AsiaOstrich/EngramGraphtheir own version, first seen Nov 8, 2026
- hyperdreamer/pi-webuitheir own version, first seen Nov 8, 2026
- AsiaOstrich/universal-dev-standardstheir own version, first seen Nov 1, 2026
- syncfusion/maui-toolkittheir own version, first seen Oct 8, 2026
- fullstackhero/dotnet-starter-kittheir own version, first seen Oct 8, 2026
Used with
Projects with it also use documentation-guide.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
volfpeterSkilldocumentation-guide
Use when writing or modifying documentation, guides, or example READMEs. Covers documentation structure, writing style, formatting conventions, cross-referencing, and code example standards.
Also in 3 projects that use this
Other versions5 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 5
- fullstackhero/dotnet-starter-kit★ 6.9ksame name
- syncfusion/maui-toolkit★ 750same name
- AsiaOstrich/universal-dev-standards★ 84same name
- hyperdreamer/pi-webui★ 9same name
- AsiaOstrich/EngramGraph★ 4same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository12 other files it gives its agents.
- commitSkill
- create-branchSkill
- create-prSkill
- create-skillSkill
- fix-ciSkill
- gh-issueSkill
- merge-to-stagingSkill
- review-pr-commentsSkill
- slack-pr-recapSkill
- start-working-on-issueSkill
- test-coverage-improveSkill
- ui-patternsSkill
The file
We split this skill into the rules it gives an agent
8 rules. 0 are common, 6 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 4 edited versions we read keep these.
6
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 16
NEVER mock
@prisma/client: - if you need Prisma client, you haven't properly mocked the repository - Distinctive: line 77
Use realistic Spanish test data for all tests:
- Distinctive: line 97
Always consider testing these:
- Distinctive: line 137
Isolate tests: Avoid shared state or order dependency
- Distinctive: line 138
One behavior per test: Follow AAA pattern (Arrange, Act, Assert)
- Distinctive: line 139
User-centric: Test components via user interactions (React Testing Library)
- Very specific: line 140
Clean up: Always restore spies and mocks in afterAll/afterEach
- Distinctive: line 147
When writing new tests, explore for existing patterns:
“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Testing Guide
Patterns and templates for writing Jest unit and integration tests. This complements the unit-tester subagent which handles test execution.
Critical Rules (Always Apply)
- NEVER import or use
@prisma/clientdirectly in any test file - NEVER mock
@prisma/client- if you need Prisma client, you haven't properly mocked the repository - ALWAYS mock the specific repository modules used by the code under test
- Never test repositories in
src/lib/repositoriesdirectly
Repository Mocking Pattern
This is the core mocking pattern. Mock the repository module, then configure return values per test.
// ✅ CORRECT: Mock repository modules
jest.mock("@/lib/repositories/userRepository", () => ({
getById: jest.fn(),
updateName: jest.fn(),
}));
const mockUserRepository = require("@/lib/repositories/userRepository");
// In your test:
mockUserRepository.getById.mockResolvedValue({
id: 1,
name: "Ana Garcia",
email: "ana@example.com",
});// ❌ WRONG: Never mock Prisma client
jest.mock("@prisma/client"); // DON'T DO THIS!External Dependencies Mocking
// Mock external libraries at module level
jest.mock("langfuse", () => ({
Langfuse: jest.fn(),
TextPromptClient: jest.fn(),
}));
// Spy on console methods
const consoleLogSpy = jest.spyOn(console, "log").mockImplementation(() => {});
afterAll(() => {
consoleLogSpy.mockRestore();
});Environment Variable Testing
- AVOID direct assignment to
process.env.NODE_ENV(TypeScript read-only) - USE
expect.any(Boolean)for environment-dependent behavior - PREFER testing actual behavior over mocking environment variables
Spanish Business Context Test Data
Use realistic Spanish test data for all tests:
const testData = {
customers: [
{ name: "Ana Garcia", phone: "+34611223344" },
{ name: "Jose Maria Fernandez-Vazquez", phone: "+34612345678" },
],
businesses: [
{ name: "Salon Bella", address: "Calle Mayor 1, Madrid" },
{ name: "Peluqueria Nona & Coiffeur", services: ["corte", "peinado"] },
],
specialChars: "Hola! Como esta usted?",
};Edge Cases Checklist
Always consider testing these:
nullandundefinedvalues- Empty objects
{}and arrays[] - Complex nested objects
- Special characters and emojis
- Circular references (where applicable)
- Functions within objects
- Large data sets
Test File Structure
__tests__/
unit/ # Unit tests (functions, hooks, utils)
integration/ # Integration tests (components, API handlers)
e2e/ # Playwright E2E test scripts
testing/
setupTests.ts # Jest global setup fileRunning Tests
| Command | Purpose |
npm test | All Jest tests |
npm test -- --coverage | With coverage report |
npm run test:watch | Watch mode |
npm run test:e2e | All Playwright E2E tests |
npm run test:e2e:smoke | Smoke tests only (fast, for PRs) |
npm run test:e2e:full | Full E2E suite (nightly) |
Best Practices
- Isolate tests: Avoid shared state or order dependency
- One behavior per test: Follow AAA pattern (Arrange, Act, Assert)
- User-centric: Test components via user interactions (React Testing Library)
- Clean up: Always restore spies and mocks in
afterAll/afterEach - Coverage target: >= 80% on critical code paths
Workflow: Finding Existing Test Patterns
When writing new tests, explore for existing patterns:
- Find similar test files:
Glob("__tests__/**/*.test.ts") - Find mock patterns:
Grep("jest.mock", path="__tests__/") - Find test setup:
Read("testing/setupTests.ts") - Find how a specific repository is mocked:
Grep("mock.*Repository", path="__tests__/")
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.

