Skip to content

Commit a03fc50

Browse files
authored
docs(agents): encourage parameterised tests in test guidelines (#2581)
1 parent 6d2402a commit a03fc50

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ See [docs/conventions.md](./docs/conventions.md).
233233
- Unit tests: Vitest.
234234
- E2E tests: Playwright.
235235
- Test core/UI services and stores with faked injected dependencies and explicit props.
236+
- 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.
236237
- Colocate tests as `.test.ts` or `.test.tsx`.
237238
- Put E2E tests in `tests/e2e/`.
238239
- After touching `@posthog/platform`, rebuild or typecheck its `dist/`.

docs/testing.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,22 @@ describe("store", () => {
9898
});
9999
```
100100

101+
## Parameterised Tests
102+
103+
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.
104+
105+
```ts
106+
it.each([
107+
{ input: "main", expected: true },
108+
{ input: "feature/x", expected: false },
109+
{ input: "", expected: false },
110+
])("isDefaultBranch($input) === $expected", ({ input, expected }) => {
111+
expect(isDefaultBranch(input)).toBe(expected);
112+
});
113+
```
114+
115+
Keep cases as separate `it` blocks when they differ in setup, assertions, or intent — parameterise repetition, not distinct behaviors.
116+
101117
## Mocking
102118

103119
Hoist mocks for modules that must be mocked before import evaluation.

0 commit comments

Comments
 (0)