- Write assertions as
expect(actual).toEqual(expected). - Do not use
toBefor these normalization tasks unless explicitly requested. - Do not use
toContain. - In Vitest, use
test()and do not useit(). - Enforce
1 test() = 1 expect(). - First try to merge multiple field-level assertions into one object-level assertion.
- If concerns are different, split into multiple
test()blocks. - If the same pattern repeats across cases, use
test.each().
- Declare
const expected = ...as the first statement in eachtest(...)function. - Then declare inputs/fixtures.
- Then declare
actual.
- For object literals and array literals in tests, use
as const satisfies .... - Use
Parameters<T>orReturnType<T>in thesatisfiestype source. - Do not add direct variable type annotations such as
const v: string[] = []. - Use
satisfies-based typing instead. - Prefer
Parameters<T>/ReturnType<T>for type derivation to avoid extra type imports. - Always try to reduce import lines, even by one line, when the same type can be derived locally.
- If the same type expression appears 3 or more times, define a type alias at file top.
- Keep alias names short, contextual, and consistent within the file.
- For expected value typing, use
type Expected = ....
- Keep implementation and tests 1:1 by function.
- Do not keep multiple function tests in one test file.
- If tests are split by function, split implementation files accordingly.
- Keep imports aligned with split files.
- Preserve existing behavior.
- Prefer minimal diffs.
- Run only affected tests and report pass/fail.