Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ See [docs/conventions.md](./docs/conventions.md).
- Unit tests: Vitest.
- E2E tests: Playwright.
- Test core/UI services and stores with faked injected dependencies and explicit props.
- Prefer a parameterised test shape (`it.each`/`test.each`) when several cases exercise the same logic with different inputs and expectations. Keep separate tests when cases differ in setup, assertions, or intent.
- Colocate tests as `.test.ts` or `.test.tsx`.
- Put E2E tests in `tests/e2e/`.
- After touching `@posthog/platform`, rebuild or typecheck its `dist/`.
Expand Down
16 changes: 16 additions & 0 deletions docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,22 @@ describe("store", () => {
});
```

## Parameterised Tests

Prefer a parameterised test shape when several cases exercise the same logic with different inputs and expectations. Use Vitest's `it.each` / `test.each` instead of copy-pasting near-identical `it` blocks.

```ts
it.each([
{ input: "main", expected: true },
{ input: "feature/x", expected: false },
{ input: "", expected: false },
])("isDefaultBranch($input) === $expected", ({ input, expected }) => {
expect(isDefaultBranch(input)).toBe(expected);
});
```

Keep cases as separate `it` blocks when they differ in setup, assertions, or intent — parameterise repetition, not distinct behaviors.

## Mocking

Hoist mocks for modules that must be mocked before import evaluation.
Expand Down
Loading