/vitest:vitest-test-conventionsfrom vitest
Provides Vitest and NestJS-specific testing patterns including test types (unit, integration, E2E), test doubles (vi.fn, vi.spyOn, vi.mock), it.each format selection, structured assertions, and integration test setup with Test.createTestingModule.
Ships in vitest. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
The cross-language testing principles (DAMP, AAA, spy over mock, what NOT to test, factories, structured assertions) are defined in
craft:testing-principles. This skill keeps Vitest / NestJS-specific patterns.
See also:
vitest-tdd-workflowfor TDD workflow and iteration patterns.
| Test Type | Setup | File pattern |
|---|---|---|
| Unit | No DI container, pure logic | *.spec.ts |
| Integration | NestJS Test.createTestingModule() | *.integration-spec.ts |
| E2E | supertest + full app | *.e2e-spec.ts |
vi.fn() // Standalone callback or function double; a port gets an in-memory stub instead
vi.spyOn() // Wraps one method of a real object, leaving the rest real
vi.mock() // Module-level replacement, for what cannot be injected
When writing test doubles, parameterized tests, or factory functions, read
references/test-examples.mdfor completevi.fn/spyOn/mockpatterns,it.eachexamples, and factory patterns.
it.each() Format Selection${}).When writing exception tests or NestJS integration tests, read
references/test-examples.mdfortoThrowpatterns andTest.createTestingModulesetup.
// Compare full object
expect(result).toEqual({ id: 1, name: 'Alice' });
// Partial match
expect(result).toEqual(expect.objectContaining({ id: 1 }));
// references/test-examples.md has the complete pattern
const module = await Test.createTestingModule({
providers: [ReceiptService, { provide: RepositoryToken, useClass: InMemoryRepo }],
}).compile();
const service = module.get(ReceiptService);
Before changing behaviour no test pins, freeze the inputs and compare today's output, quirks included, to a committed golden file. The order, the gates and the retirement rules live in craft:testing-principles §16.
it('keeps today\'s summaries, quirk included', () => {
const frozen = [summarize('R-1', [10, 2.5, 0]), summarize('R-0', [])];
const golden = readFileSync(new URL('./receipt-summary.golden.txt', import.meta.url), 'utf8');
expect(`${frozen.join('\n')}\n`).toBe(golden);
});
The golden file is plain text read with node:fs: no snapshot API.
| Situation | Approach |
|---|---|
| Simple value objects | Direct instantiation |
| Port dependency | In-memory stub that is its own spy |
| Spy on real method | vi.spyOn() |
| Module replacement | vi.mock() |
| Same logic, different data | it.each() (object or template literal) |
| Verify method called | expect(spy).toHaveBeenCalledWith(...) after act |
| Compare objects | toEqual + expect.objectContaining |
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
2 skills in this plugin
Other plugins' skills for the same job
npx claudepluginhub fabiensalles/claude-marketplace --plugin vitest