Loading...
Loading...
Vitest testing framework for unit, component, and integration tests. Covers test structure (describe/it/test.each), assertions with expect, lifecycle hooks, mocking (vi.fn/vi.mock/vi.spyOn), React Testing Library patterns, hook testing with renderHook, user-event interactions, async utilities, configuration, workspace setup, coverage, and advanced patterns like in-source testing and concurrent execution. Use when writing unit tests, component tests, integration tests, or testing React hooks. Use for test configuration, mocking modules, testing async behavior, snapshot testing, or setting up test coverage.
npx skill4agent add oakoss/agent-skills vitest-testing| Pattern | API | Key Points |
|---|---|---|
| Test structure | | Organize related tests |
| Single test | | Both are aliases |
| Parameterized tests | | Run same test with different inputs |
| Concurrent tests | | Run tests in parallel |
| Skip test | | Conditionally skip tests |
| Only test | | Run specific test for debugging |
| Assertions | | Compare primitive values |
| Deep equality | | Compare objects/arrays |
| Async assertions | | Test promise resolution |
| Before each test | | Setup before each test |
| After each test | | Cleanup after each test |
| Mock function | | Create spy function |
| Mock module | | Replace entire module |
| Spy on method | | Track calls to existing method |
| Clear mocks | | Clear call history |
| Fake timers | | Control setTimeout/setInterval |
| Render component | | Mount React component for testing |
| Query by role | | Find elements by accessibility role |
| User interaction | | Simulate user events |
| Wait for change | | Wait for async changes |
| Find async element | | Query + wait combined |
| Render hook | | Test custom hooks |
| Update hook props | | Re-render hook with new props |
| Snapshot | | Compare against saved snapshot |
| Inline snapshot | | Snapshot stored in test file |
| Mistake | Correct Pattern |
|---|---|
Using | Use |
| Testing implementation details | Test behavior and public API |
Using | Prefer |
Missing | Always call |
| Shared state between tests | Use |
| Not cleaning up mocks | Use |
| Mocking too much | Only mock external dependencies and APIs |
| Not disabling retries in tests | Set |
| Immediate assertions on async | Use |
| Creating QueryClient in render | Create once in wrapper or use |
| Testing library code | Trust the library, test your usage |
| Not awaiting user events | All |
Using | |
| Inline select without memoization | Extract to stable function for TanStack Query |
ExploreTaskplaywrightcode-reviewer