testing-mock-async-hygiene

Enforces correct mock ordering, async setup awaiting, and selector practices in test suites.

Updated Mar 30, 2026
One-click install
npx skills add https://github.com/ZaxbyHub/ragappv3 --skill testing-mock-async-hygiene-zaxbyhub
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: testing-mock-async-hygiene
Source: https://github.com/ZaxbyHub/ragappv3/tree/main/.opencode/skills/generated/testing-mock-async-hygiene
Command: npx skills add https://github.com/ZaxbyHub/ragappv3 --skill testing-mock-async-hygiene-zaxbyhub

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Tests that fail for the wrong reasons waste debugging time: mocks consuming each other's responses, async initialization not awaited before handlers fire, and brittle selectors breaking on unrelated changes. This Skill defines a checklist of procedures and forbidden shortcuts that keep mocks, async setup, and assertions aligned with the code under test. ## Core Features & Use Cases - Mock Ordering Rules: Use URL-routed mockImplementation and chain mockResolvedValueOnce calls in the exact order API calls occur when multiple endpoints are mocked in one test. - Async Setup Discipline: Await all async initialization and state-population before triggering handlers, and ensure async mocks resolve before dependent code runs. - Failure Triage Guidance: Treat failures mentioning mocks or defensive handling as contract divergence, and verify the test environment (node_modules, TypeScript version, lockfile) before blaming implementation. - Use Case: A component test fails after a function's return signature changed to a tuple. The Skill directs you to audit all direct-call test sites and their unpacking patterns instead of weakening assertions. ## Quick Start Review my failing component test and check whether the mock setup order and async initialization match the code under test.

Frequently Asked Questions about testing-mock-async-hygiene

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

FAQPage Schema
How do I mock multiple API endpoints in a single test?▼

Use mockImplementation with URL routing so each endpoint returns its own response, or chain mockResolvedValueOnce calls in the exact order the API calls will occur. This prevents one mock from consuming another mock's response.

How to test components with async initialization?▼

Await all async setup and state-population operations before triggering the event handlers under test. Async mocks must resolve before any code that depends on their resolved value executes.

Why do tests fail with errors mentioning mocks or defensive handling?▼

Such failures usually indicate the implementation diverged from the contract defined by the tests, not a broken test. Investigate the implementation behavior the test verifies before changing the test itself.

What selectors should I use instead of CSS class names in tests?▼

Use data-testid attributes or semantic role and text selectors, especially when multiple similar elements exist. Class-name assertions are brittle and can target a sibling element with a similar tag.

What should I check before blaming implementation for test failures?▼

Verify the test environment matches the baseline: node_modules state, TypeScript version, and lockfile consistency. Only attribute failures to implementation after the environment is confirmed consistent.

What breaks when a function's return signature changes to a tuple?▼

All direct-call test sites and their unpacking patterns must be audited and updated. Relying on implicit tuple length matching for assertions is a forbidden shortcut that hides contract drift.