macalbert/envilder/typescript-test-doubles
Claude Code and agent skill by macalbert/envilder
- community
Checking that the SKILL.md file is still in the repository.
Test doubles with Vitest (vi.fn, vi.mock, vi.spyOn) and Mother pattern. Use when creating test data, mocking dependencies, or setting up module mocks in TypeScript tests.
Install
npx vskill@latest install macalbert/envilder/typescript-test-doublesSKILL.md
Test Doubles (TypeScript)
This skill defines how to use test doubles in TypeScript (Vitest).
Test Doubles Types
1. Mock: vi.fn()
Use vi.fn() to create mock functions for port interfaces.
Purpose: Replace real dependencies with controllable test doubles.
2. Stub: mockResolvedValue / mockReturnValue
Use return value methods to configure stubs.
Purpose: Predefined responses without caring about call verification.
3. Spy: vi.spyOn()
Use vi.spyOn() to observe calls on real objects without replacing behavior.
Purpose: Verify interactions while preserving real implementation.
4. Module Mock: vi.mock()
Use vi.mock() to replace entire modules.
Purpose: Replace external dependencies (AWS SDK, file system, etc.).
5. Error Simulation: mockRejectedValue
Use mockRejectedValue() to simulate failures.
Purpose: Test error paths and exception handling.
Verification Patterns
Basic Verification
Not Called
Call Order
Argument Matchers
Mother Pattern
Use factory functions for reusable test data creation.
Usage:
Port Test Double Pattern
Build complete mock objects implementing domain interfaces:
Summary
| Double Type | Vitest API | Purpose | |
|---|---|---|---|
| Mock | vi.fn() | Controllable replacement | |
| Stub | .mockResolvedValue() / .mockReturnValue() | Predefined responses | |
| Spy | vi.spyOn() | Observe real objects | |
| Module mock | vi.mock() | Replace entire modules | |
| Error sim | .mockRejectedValue() | Failure paths |
When writing tests:
- Create port test doubles with
vi.fn()inbeforeEach - Configure stubs with
.mockResolvedValue()in Arrange - Always verify mock interactions in Assert
- Use Mother pattern for complex test data
- Prefer
vi.fn()overvi.mock()(port-level > module-level)
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryChecking.github/skills/typescript-test-doubles/SKILL.md
Popularity
- Repository stars
- 136
- Repository forks
- 4
- 7-day trend score
- 25
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 26 Jun 2026, 4 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/macalbert/envilder/typescript-test-doubles)