mocking-strategies

Isolate external dependencies in Python and JavaScript tests with mocking patterns.

39|6|Updated Feb 9, 2026
One-click install
npx skills add https://github.com/vladkesler/initrunner --skill mocking-strategies-vladkesler
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: mocking-strategies
Source: https://github.com/vladkesler/initrunner/tree/main/examples/roles/unit-tester/skills/mocking-strategies
Command: npx skills add https://github.com/vladkesler/initrunner --skill mocking-strategies-vladkesler

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Mocking strategies for isolating external dependencies in tests.

Core Features & Use Cases

  • Python mocking: patch("module.path.ClassName"), patch.object, MagicMock with spec, side_effect, return_value, monkeypatch (pytest built-in)
  • JavaScript mocking: jest.mock, vi.mock, manual mocks, dependency injection, msw
  • When to mock; When NOT to mock; Mock verification; MUST; MUST NOT guidelines.

Quick Start

Apply Python or JavaScript mocking patterns to isolate dependencies in your tests.

Frequently Asked Questions about mocking-strategies

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I isolate external dependencies in Python tests using mocking?

Isolate external dependencies in Python tests using unittest.mock by patching module boundaries with patch, MagicMock with spec, side_effect, and return_value to replace database or API calls. Pytest's monkeypatch is also supported for modifying attributes during test runs.

What is the best way to mock APIs and databases in JavaScript testing?

The best way to mock APIs and databases in JavaScript testing is using jest.mock or vi.mock to replace modules. You can also use manual mocks, dependency injection, or msw to isolate external HTTP requests and control return values.

When should I not use mocking in unit and integration tests?

You should not use mocking when testing core logic or simple pure functions, as over-mocking can hide integration failures. Follow MUST NOT guidelines to avoid replacing internal code and only mock external dependencies like databases or APIs to maintain test reliability.

How do I verify mock calls and side effects in Python and JavaScript?

Verify mock calls and side effects in Python by inspecting MagicMock attributes like call_count and assert_called_with, and in JavaScript by using jest or vi mock verification methods. Ensure spec-enabled mocks are used to prevent calling non-existent methods during verification.

Does this mocking approach work with both pytest and Jest frameworks?

Yes, this mocking approach works with both pytest and Jest frameworks. It provides specific patterns for Python using unittest.mock and pytest monkeypatch, alongside JavaScript patterns for Jest and Vitest using jest.mock, vi.mock, and msw.