← All skills

Jest Skill

Unit testingJavaScriptTypeScript

Copy and Paste in your Terminal

npx skills add https://github.com/LambdaTest/agent-skills.git --skill jest-skill

Overview

When to Apply: Reference when writing JavaScript/TypeScript unit tests, mocking modules or functions, testing React components with Testing Library, or using snapshot testing for UI components. Triggers on "Jest", "expect().toBe()", "jest.mock", "snapshot test", "React test".

Rule Categories by Priority:

PriorityCategoryImpactPrefix
1Mocking StrategyCRITICALmock-
2Assertion PatternCRITICALassert-
3Async TestingHIGHasync-
4React TestingHIGHreact-
5Snapshot TestingMEDIUMsnapshot-
6Table-Driven TestsMEDIUMtable-
7Custom MatchersLOW-MEDIUMmatcher-
8CI/CD & ConfigLOWci-

Quick Reference:

  1. Mocking Strategy (CRITICAL) mock-return-valueUse mockReturnValue/mockResolvedValue for deterministic tests mock-module — Use jest.mock('./module') for dependency isolation mock-spy-restore — Always restore spies with spy.mockRestore() mock-fake-timers — Use jest.useFakeTimers() for time-dependent code
  2. Assertion Pattern (CRITICAL) assert-specific-matcherUse expect(x).toBe(y) not expect(x === y).toBe(true) assert-await-async — Always await async assertions to prevent swallowed failures assert-to-equal-objects — Use toEqual for deep equality, toBe for primitives
  3. React Testing (HIGH) react-user-eventPrefer userEvent over fireEvent for realistic interactions react-get-by-role — Use getByRole/getByLabelText for accessible queries react-wait-for — Use waitFor for async state updates

Playbook Deep Dive (12 sections): §1 Production Config · §2 Mocking Deep Dive · §3 Async Patterns · §4 Table-Driven Tests (test.each) · §5 Custom Matchers · §6 React Testing (Testing Library) · §7 Snapshot Testing · §8 Testing API Services · §9 Global Setup/Teardown & Projects · §10 CI/CD Integration · §11 Debugging Table (10 problems) · §12 Best Practices (15 items)

The agent loads from 2 on-demand reference files (advanced-patterns.md, playbook.md) containing detailed implementation guides, cloud integration patterns, debugging tables, and language-specific best practices.


For full reference, implementation samples, and cloud setup, see the Documentation, Playbook, Advanced patterns tabs.