test-writer
Create and maintain tests for the Raamattu Nyt monorepo using Vitest and React Testing Library. Use when: - Writing new tests for hooks, components, or utility functions - Analyzing recent git commits to identify code needing tests - Reviewing existing tests for correctness and coverage - Creating mocks for Supabase, auth, or other dependencies - Debugging test failures or flaky tests Triggers: "write tests", "test this", "add tests", "need tests for", "analyze test coverage", "fix failing tests", "mock this", "review tests"
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
Test Writer
Write and maintain tests for the Raamattu Nyt monorepo.
Context Files (Read First)
For structure and conventions, read from Docs/context/:
-
Docs/context/repo-structure.md- Where test files go -
Docs/context/conventions.md- Naming patterns
Quick Start
# Run all tests
npm test
# Run with coverage
npm run test:coverage
# Run specific test file
npx vitest run path/to/file.test.ts
Test File Conventions
- Place tests adjacent to source:
useHook.ts→useHook.test.ts - Use
.test.tsfor pure logic,.test.tsxfor React components/hooks - Name:
describe("ComponentName")ordescribe("hookName")
Standard Test Structure
import { describe, expect, it, vi, beforeEach } from "vitest";
// Mocks BEFORE imports (hoisted)
vi.mock("@/integrations/supabase/client", () => ({
supabase: { rpc: vi.fn() }
}));
// Import module under test AFTER mocks
import { myFunction } from "./myModule";
describe("myFunction", () => {
beforeEach(() => {
vi.clearAllMocks();
});
it("does expected behavior", () => {
expect(myFunction()).toBe(expected);
});
});
Hook Testing Pattern
import { renderHook, waitFor } from "@testing-library/react";
// Wrapper for context providers
const wrapper = ({ children }) => (
<AuthProvider>{children}</AuthProvider>
);
it("returns initial state", () => {
const { result } = renderHook(() => useMyHook(), { wrapper });
expect(result.current.loading).toBe(true);
});
it("updates on async action", async () => {
const { result } = renderHook(() => useMyHook(), { wrapper });
await waitFor(() => {
expect(result.current.data).toBeDefined();
});
});
Common Mocks
See references/mocks.md for reusable mock patterns:
- Supabase client (RPC, auth, schema queries)
- useAuth hook
- React Query
- localStorage
Workflow
-
Identify what to test
- Use
code-wizardskill to find the file/function - Check git log for recent changes:
git log --oneline -20
- Use
-
Check existing tests
- Find tests:
Glob pattern: **/*.test.{ts,tsx} - Read related test files for patterns
- Find tests:
-
Write tests covering
- Happy path (normal operation)
- Error cases (API failures, invalid input)
- Edge cases (empty arrays, null, undefined)
- Loading states for async operations
-
Run and verify
npx vitest run path/to/file.test.ts
Test Quality Checklist
- Tests are independent (no shared state between tests)
- Mocks are cleared in
beforeEach - Async operations use
waitFornot arbitrary delays - Error scenarios are tested
- Edge cases covered (null, empty, boundary values)
Related Skills
| Situation | Delegate To |
|---|---|
| Find code to test | code-wizard |
| Debug test failures | systematic-debugging |
| CI test failures | ci-doctor |
| Lint errors in tests | lint-fixer |
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-01-20
- 索引更新时间
- 2026-01-26
- Branch
- main
收录与同步日期属于本站记录。源码修改历史请查看来源仓库。
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!