Tests should assert the behavior contract precisely, include the missing coverage for changed code, and stay isolated/noisy-control friendly.
Key rules:
toBe; if structure matters too, also use toStrictEqual.main), including edge paths (e.g., false branches).expectTypeOf and write assertions that trigger the specific TypeScript checks you care about (e.g., excess properties).console when tests expect errors to be logged.Example (identity + deep equality):
const options = mutationOptions({ mutationKey: ['key'], mutationFn: () => Promise.resolve(5) })
expect(options).toBe(options) // referential identity
expect(options).toStrictEqual({ mutationKey: ['key'], mutationFn: expect.any(Function) })
Example (time-based intermediate assertions):
render(BaseExample, { props: { options: { queries: [/* key1 resolves at 10ms, key2 at 20ms */] } } })
expect(getByText('Status 1: pending')).toBeInTheDocument()
await vi.advanceTimersByTimeAsync(11)
expect(getByText('Status 1: success')).toBeInTheDocument()
await vi.advanceTimersByTimeAsync(10)
expect(getByText('Status 2: success')).toBeInTheDocument()
Example (type-test style):
expectTypeOf(infiniteQueryOptions)
.parameter(0)
.not.toHaveProperty('stallTime')
Enter the URL of a public GitHub repository