Full standards in jest.md. Always-on summary:
Structure:
- One
describe(per module/class; onedescribe(per method inside - Test names complete the sentence:
it('returns null when user not found') - Use
expect(for all assertions — Arrange-Act-Assert with blank lines between sections
Setup / teardown:
beforeEach(to reset state before each test; calljest.clearAllMocks(inbeforeEachto prevent cross-test pollution
Mocking:
jest.mock(calls go at the top of the file, before imports take effect- Use
mockReturnValue(ormockResolvedValue(to control return values - Mock at the system boundary (HTTP, DB, filesystem) — not internal functions
jest.spyOn()for partial mocks where you want the real implementation for some calls- Always restore mocks: use
jest.restoreAllMocks()inafterEachorrestoreMocks: truein config
Async:
- Always
returnorawaitpromises — an unawaited assertion can silently pass - Use
jest.useFakeTimers()forsetTimeout/setIntervaltests; always calljest.useRealTimers()inafterEach
Coverage:
- Set thresholds in
jest.config.ts— don't chase 100%; target branches and functions /* istanbul ignore next */— use sparingly with a comment explaining why
Never:
it.only()ordescribe.only()merged to main — use--testNamePatternin dev- Test implementation details — test behaviour observable from the outside
- Assertions inside loops — extract to helpers or use
test.each
Related skills: Your frontend or backend layer (framework-specific setup), mocking/msw (HTTP mocking for integration tests)
Source: manikumarkv/devrunway-claude-plugin — distributed by TomeVault.