mocking-network-and-time

Stubs network dependencies and freezes clocks to make tests deterministic.

113|17|Updated Oct 5, 2025
One-click install
npx skills add https://github.com/jaktestowac/awesome-copilot-for-testers --skill mocking-network-and-time-jaktestowac
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: mocking-network-and-time
Source: https://github.com/jaktestowac/awesome-copilot-for-testers/tree/main/plugins/mocking-network-and-time/skills/mocking-network-and-time
Command: npx skills add https://github.com/jaktestowac/awesome-copilot-for-testers --skill mocking-network-and-time-jaktestowac

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Tests that depend on third-party APIs, payment sandboxes, wall clocks, or timezones are slow, flaky, and unrepeatable. This Skill decides what to fake and what to keep real, then stubs the dependency correctly so the suite stops failing for reasons outside your code. ## Core Features & Use Cases - Network interception: Stub or modify HTTP traffic with Playwright route, replay recorded HAR files, or share MSW handlers across unit, component, and browser tests. - Time and environment control: Pin the instant, timezone, and locale together using Playwright clock, Vitest fake timers, or Jest, with recipes for DST, leap-day, and year-boundary cases. - Drift guards and fidelity records: Every mock gets a contract check, HAR refresh command, or unmocked smoke test, plus a written record of what the mock stops catching. - Use Case: A checkout test fails whenever the payment sandbox rate-limits. Use this Skill to route-stub the declined-card and timeout responses, freeze the clock for session-expiry assertions, and record a nightly unmocked smoke test as the drift guard. ## Quick Start Ask the assistant to stabilize a flaky test file by mocking its third-party API calls and pinning the clock and timezone, following the mocking-network-and-time workflow.

Frequently Asked Questions about mocking-network-and-time

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

FAQPage Schema
How do I mock API requests in Playwright tests?▼

Use page.route or context.route with a precise method-and-path matcher, then call route.fulfill with a realistic status, headers, and body. Register a catch-all route that throws on unmocked traffic so renamed endpoints fail loudly instead of passing through.

MSW vs Playwright route: which should I use for mocking?▼

Use MSW for component and integration tests where handlers are shared across runners, and Playwright route for browser end-to-end tests since it sits below the application. Avoid running both on the same call; pick one interception layer per suite.

How do I freeze time in Vitest or Playwright tests?▼

In Vitest call vi.useFakeTimers with vi.setSystemTime and restore with vi.useRealTimers in afterEach. In Playwright use page.clock.install with a fixed date, then fastForward or setFixedTime, and pin timezoneId and locale in the config.

Should I mock my own backend in end-to-end tests?▼

No. End-to-end tests should keep your own stack real and mock only what you do not own, such as third-party APIs or payment providers. Mocking your own API in an E2E test turns it into an integration test and hides contract breaks.

Why does my mocked test pass while production is broken?▼

The mock has drifted from the real dependency. Add a drift guard: a contract check against the real spec, a documented HAR refresh command, or a thin unmocked smoke test run on a schedule, and record when it was last verified.

When should I use HAR replay instead of handwritten stubs?▼

Use HAR replay for end-to-end tests against a large read-only API surface you do not want to hand-write. Always set notFound to 'abort', strip secrets before committing, and treat a HAR older than the API's release cadence as expired.