testing

Run targeted Vitest tests and apply vi.spyOn mock strategies to fix failing suites.

1|Updated May 9, 2026
One-click install
npx skills add https://github.com/duwenji/generative-ai-oss-tutorials --skill testing-duwenji
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing
Source: https://github.com/duwenji/generative-ai-oss-tutorials/tree/main/sandbox/lobe-chat/.agents/skills/testing
Command: npx skills add https://github.com/duwenji/generative-ai-oss-tutorials --skill testing-duwenji

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

It reduces flaky and hard-to-debug test failures by providing clear Vitest conventions for running, structuring, mocking, and iteratively fixing tests without overfitting to implementation details.

Core Features & Use Cases

  • Targeted test execution: Run single files or package-specific tests to speed up feedback loops.
  • Safer mocking strategy: Prefer vi.spyOn and controlled browser/global stubs rather than broad module mocks.
  • Failure triage workflow: Decide whether to update assertions (behavior changes) or stop and escalate after repeated unsuccessful fixes.
  • Security-aware expectations: Reinforce that tests should verify externally observable behavior, not internal wiring.
  • Practical references: Use deeper scenario docs for database model testing, Electron IPC, Zustand store actions, agent runtime E2E, and desktop controller units.

Quick Start

Run the specific failing test file with vitest using bunx and then adjust only behavior-focused expectations until the test passes.

Frequently Asked Questions about testing

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

FAQPage Schema
How do I debug flaky Vitest tests without overfitting to internal implementation details?

Fix flaky Vitest tests by running targeted single files, adjusting only behavior-focused expectations, and verifying externally observable behavior rather than internal wiring to prevent overfitting.

What is the best way to configure mocks in Vitest for browser and module boundaries?

Configure mocks in Vitest by preferring `vi.spyOn` and controlled browser/global stubs over broad `vi.mock` usage to maintain test reliability and avoid over-broad module mocking.

How do I run package-specific Vitest tests to speed up my feedback loop?

Speed up feedback loops by running package-specific Vitest tests through targeted single-file execution with bunx, enabling iterative fixes and faster validation of behavior-focused expectations.

When should I update assertions versus escalate repeated Vitest test failures?

Update Vitest assertions when behavior changes are intended, but stop and escalate repeated failures after unsuccessful fixes to prevent overfitting and ensure tests verify true externally observable behavior.

Does Vitest support E2E testing and mocking for Electron IPC and Zustand store actions?

Vitest supports E2E testing and mocking for Electron IPC, Zustand store actions, database models, and desktop controllers by consulting reference guides for advanced scenario execution and robust mock strategies.

Why should I avoid over-broad vi.mock usage in my unit testing strategy?

Avoid over-broad `vi.mock` usage in unit testing because it creates flaky failures; preferring `vi.spyOn` ensures tests verify externally observable behavior through safer, more controlled mocking strategies.