mirror of
https://github.com/duthaho/claudekit.git
synced 2026-06-10 20:24:57 +03:00
3.2 KiB
3.2 KiB
name, description
| name | description |
|---|---|
| testing | Use when writing, debugging, or configuring unit or integration tests with pytest, Vitest, or Jest. Also activate for fixtures, mocking, coverage, parametrization, jest.mock, vi.mock, jest.fn, vi.fn, conftest.py, vitest.config.ts, jest.config, Testing Library, @jest/globals, or any test configuration. |
Testing
When to Use
- Writing Python tests with pytest (fixtures, parametrize, markers, coverage)
- Testing JavaScript/TypeScript with Vitest (React components, mocking, workspace)
- NestJS or existing projects using Jest
- Debugging test configuration, ESM issues, or flaky tests
- Setting up coverage, CI integration, or test infrastructure
When NOT to Use
- E2E browser testing — use
playwright - Testing anti-patterns and methodology — use
testing-anti-patterns - TDD workflow — use
test-driven-development
Quick Reference
| Framework | Reference | Key features |
|---|---|---|
| pytest | references/pytest.md |
Fixtures, parametrize, conftest, markers, coverage, async tests |
| Vitest | references/vitest.md |
vi.mock, vi.fn, Testing Library, MSW, workspace, coverage |
| Jest | references/jest.md |
jest.mock, jest.fn, @jest/globals, NestJS testing, migration to Vitest |
Best Practices
- Name tests descriptively.
test_[function]_[scenario]_[expected](Python) orit('should [behavior]')(JS/TS). - Keep tests independent. Never rely on execution order. Each test sets up its own state.
- One assertion focus per test. Multiple asserts OK if verifying the same behavior.
- Mock at the boundary, not in the middle. Mock external services, databases, and network calls. Don't mock internal functions.
- Clear/restore mocks between tests.
vi.clearAllMocks()inbeforeEachorjest.restoreAllMocks()inafterEach. - Use
userEventoverfireEventfor React component testing (simulates real user behavior). - Query by role and label, not test IDs (
getByRole,getByLabelTextovergetByTestId). - Run the full suite in CI with branch coverage. Local development can use
-xfor fast feedback.
Common Pitfalls
- Forgetting to
awaitin async tests. Omittingawaitmakes tests pass vacuously. - Mock hoisting confusion.
vi.mock()/jest.mock()calls are hoisted — variables referenced in mock implementations may be undefined. - Shared mutable fixtures. A module-scoped fixture returning a mutable object gets modified by one test and breaks another.
- Patching the wrong import path. Patch where the import is looked up, not where it's defined.
- Snapshot overuse. Developers update snapshots without reviewing diffs. Prefer explicit assertions.
- Not cleaning up fake timers. Forgetting
vi.useRealTimers()inafterEachbreaks subsequent tests. - Testing implementation, not behavior. Assert on outcomes, not internal method calls.
- Running Jest where Vitest fits. For new Vite/React/Next.js projects, Vitest is strictly better.
Related Skills
testing-anti-patterns— Common testing mistakes to avoidtest-driven-development— TDD workflowplaywright— End-to-end browser testing