advanced-js-mocking-patterns
Advanced mocking patterns for Jest and Vitest including module mocking, spies, and fake timers. PROACTIVELY activate for: (1) Module mocking, (2) Partial mocking with spies, (3) Mock lifecycle management, (4) Fake timers for time-dependent code, (5) Complex mock implementations. Triggers: "jest.mock", "vi.mock", "spyOn", "fakeTimers", "mockImplementation", "mockReturnValue", "mock lifecycle"
Best use case
advanced-js-mocking-patterns is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Advanced mocking patterns for Jest and Vitest including module mocking, spies, and fake timers. PROACTIVELY activate for: (1) Module mocking, (2) Partial mocking with spies, (3) Mock lifecycle management, (4) Fake timers for time-dependent code, (5) Complex mock implementations. Triggers: "jest.mock", "vi.mock", "spyOn", "fakeTimers", "mockImplementation", "mockReturnValue", "mock lifecycle"
Teams using advanced-js-mocking-patterns should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/advanced-js-mocking-patterns/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How advanced-js-mocking-patterns Compares
| Feature / Agent | advanced-js-mocking-patterns | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Advanced mocking patterns for Jest and Vitest including module mocking, spies, and fake timers. PROACTIVELY activate for: (1) Module mocking, (2) Partial mocking with spies, (3) Mock lifecycle management, (4) Fake timers for time-dependent code, (5) Complex mock implementations. Triggers: "jest.mock", "vi.mock", "spyOn", "fakeTimers", "mockImplementation", "mockReturnValue", "mock lifecycle"
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Advanced JS Mocking Patterns Skill
## Metadata (Tier 1)
**Keywords**: jest.mock, vi.mock, spyOn, fakeTimers, mockImplementation
**File Patterns**: *.test.ts, *.spec.js
**Modes**: testing_frontend, testing_backend
---
## Instructions (Tier 2)
### Module Mocking
```typescript
// Mock entire module
jest.mock('axios');
import axios from 'axios';
test('fetches data', async () => {
(axios.get as jest.Mock).mockResolvedValue({ data: { id: 1 } });
const result = await fetchUser(1);
expect(result).toEqual({ id: 1 });
});
```
### Spies (Partial Mocking)
```typescript
const obj = {
method1: () => 'original',
method2: () => 'original'
};
const spy = jest.spyOn(obj, 'method1');
spy.mockReturnValue('mocked');
obj.method1(); // 'mocked'
obj.method2(); // 'original' (not mocked)
expect(spy).toHaveBeenCalled();
```
### Mock Lifecycle
```typescript
beforeEach(() => {
jest.clearAllMocks(); // Reset call counts
});
afterEach(() => {
jest.restoreAllMocks(); // Restore original implementations
});
```
### Fake Timers
```typescript
jest.useFakeTimers();
test('debounce function', () => {
const callback = jest.fn();
const debounced = debounce(callback, 1000);
debounced();
debounced();
debounced();
jest.advanceTimersByTime(1000);
expect(callback).toHaveBeenCalledTimes(1); // Only last call
});
```
### Mock Implementations
```typescript
const mock = jest.fn()
.mockImplementationOnce(() => 'first')
.mockImplementationOnce(() => 'second')
.mockImplementation(() => 'default');
mock(); // 'first'
mock(); // 'second'
mock(); // 'default'
```
### Anti-Patterns
- Not clearing mocks between tests
- Over-mocking (testing implementation)
- Mocking internal modules
- Forgetting to restore timersRelated Skills
advanced-skill-creator
Meta-skill that generates domain-specific skills using advanced reasoning techniques. PROACTIVELY activate for: (1) Create/build/make skills, (2) Generate expert panels for any domain, (3) Design evaluation frameworks, (4) Create research workflows, (5) Structure complex multi-step processes, (6) Instantiate templates with parameters. Triggers: "create a skill for", "build evaluation for", "design workflow for", "generate expert panel for", "how should I approach [complex task]", "create skill", "new skill for", "skill template", "generate skill"
advanced-rendering
Master high-performance rendering for large datasets with Datashader. Use this skill when working with datasets exceeding 100M+ points, optimizing visualization performance, or implementing efficient rendering strategies with rasterization and colormapping techniques.
Advanced React Clean Integration
Integrate React with clean architecture without framework leakage using hooks as adapters and presenters. Use when connecting React to domain logic, designing hook-based DI, or isolating UI from business rules.
Advanced RE Analysis
Specialized reverse engineering analysis workflows for binary analysis, pattern recognition, and vulnerability assessment
advanced-patterns
Advanced T-SQL patterns and techniques for SQL Server. Use this skill when: (1) User needs help with CTEs or recursive queries, (2) User asks about APPLY operator, (3) User wants MERGE or OUTPUT clause help, (4) User works with temporal tables, (5) User needs In-Memory OLTP guidance, (6) User asks about advanced grouping (ROLLUP, CUBE, GROUPING SETS).
advanced-oscal-validator
Perform comprehensive OSCAL validation using community-inspired patterns including JSON schema validation, business rule validation, cross-reference checking, and best practices from IBM Trestle, oscal-pydantic, and Lula. Use for thorough document quality assurance.
Advanced Modular Library Design
Design modular libraries with clear package boundaries, feature-first organization, and clean API surfaces. Use when structuring monorepos, defining module boundaries, or designing library APIs.
advanced-memory-skill-creator
Use when planning, scaffolding, validating, or packaging Claude skills inside Advanced Memory MCP.
advanced-memoization-strategies
Apply principled memoization techniques to reduce re-rendering without introducing correctness bugs.
advanced-math-trading/robustness-risk
Tail risk, EVT, regularization, validation guardrails, and common pitfalls.
advanced-math-trading/portfolio-factors
Factor modeling and portfolio construction (Markowitz, Black-Litterman, constraints, turnover).
advanced-math-trading/foundations-core
Probability, moments/tails, Bayes, and statistical learning foundations for systematic trading.