Skip to main content
skill CX Codex

jest-skill — Claude Code skill: what it does, how to install

Produces Jest unit and integration tests across JavaScript and TypeScript, covering mocks, snapshots, and React components.

MIT 292 installs ★ 393 updated 2026-10-13

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add LambdaTest/agent-skills --skill jest-skill -a claude-code
Open on GitHub

What jest-skill does

The skill supplies structured Jest patterns spanning basic assertions, module isolation, and promise testing. It includes standard matchers for objects, numbers, and exceptions, alongside spy setups and fake timer manipulations with jest.advanceTimersByTime.

UI coverage focuses on @testing-library/react workflows, testing form submissions, element queries, and asynchronous expectations via waitFor. Rules also guard against common pitfalls like missing await statements or snapshot overuse.

Because component examples rely on React Testing Library, your repository needs @testing-library/react and @testing-library/jest-dom installed to execute the resulting specs.

What it helps with

  • build async Jest tests checking rejected and resolved promises
  • mock modules and monitor function calls using jest.spyOn
  • verify React form submissions with Testing Library queries
  • create component snapshot assertions using renderer outputs

Example prompts for the agent

  • Generate a Jest test suite for an API client using jest.mock
  • Write a React component test for LoginForm with screen queries and fireEvent
  • Add table-driven Jest tests verifying custom error throws

How to install jest-skill

1Skills CLI (Vercel)

npx skills add LambdaTest/agent-skills --skill jest-skill -a claude-code

2Manually: put the files in place

~/.claude/skills/jest-skill/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/jest-skill/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about jest-skill

How to install jest-skill in Claude Code?

Run npx skills add LambdaTest/agent-skills --skill jest-skill -a claude-code in your terminal.

What does jest-skill do?

It guides code assistants in writing TypeScript and JavaScript test suites using Jest, covering matchers, timers, and mocks.

Which languages are supported?

The skill handles both JavaScript and TypeScript.

Source text

SKILL.md · MIT
---
name: jest-skill
description: >
  Generates Jest unit and integration tests in JavaScript or TypeScript.
  Covers mocking, snapshots, async testing, and React component testing.
  Use when user mentions "Jest", "describe/it/expect", "jest.mock",
  "toMatchSnapshot". Triggers on: "Jest", "expect().toBe()", "jest.mock",
  "snapshot test", "JS test", "React test".
languages:
  - JavaScript
  - TypeScript
category: unit-testing
license: MIT
metadata:
  author: TestMu AI
  version: "1.0"
---

# Jest Testing Skill

## Core Patterns

### Basic Test

```javascript
describe('Calculator', () => {
  let calc;
  beforeEach(() => { calc = new Calculator(); });

  test('adds two numbers', () => {
    expect(calc.add(2, 3)).toBe(5);
  });

  test('throws on division by zero', () => {
    expect(() => calc.divide(10, 0)).toThrow('Division by zero');
  });
});
```

### Matchers

```javascript
expect(value).toBe(exact);                 // === strict
expect(value).toEqual(object);             // deep equality
expect(value).toBeTruthy();
expect(value).toBeNull();
expect(value).toBeGreaterThan(3);
expect(value).toBeCloseTo(0.3, 5);
expect(str).toMatch(/regex/);
expect(arr).toContain(item);
expect(arr).toHaveLength(3);
expect(obj).toHaveProperty('name');
expect(obj).toMatchObject({ name: 'Alice' });
expect(() => fn()).toThrow(CustomError);
```

### Mocking

```javascript
// Mock function
const mockFn = jest.fn();
mockFn.mockReturnValue(42);
mockFn.mockResolvedValue({ data: 'test' });
expect(mockFn).toHaveBeenCalledWith('arg1');
expect(mockFn).toHaveBeenCalledTimes(1);

// Mock module
jest.mock('./database');
const db = require('./database');
db.getUser.mockResolvedValue({ name: 'Alice' });

// Mock with implementation
jest.mock('./api', () => ({
  fetchUsers: jest.fn().mockResolvedValue([{ name: 'Alice' }]),
}));

// Spy
const spy = jest.spyOn(console, 'log').mockImplementation();
expect(spy).toHaveBeenCalledWith('expected');
spy.mockRestore();

// Fake timers
jest.useFakeTimers();
jest.advanceTimersByTime(1000);
jest.useRealTimers();
```

### Async Testing

```javascript
test('fetches users', async () => {
  const users = await fetchUsers();
  expect(users).toHaveLength(3);
});

test('resolves with data', () => {
  return expect(fetchData()).resolves.toEqual({ data: 'value' });
});

test('rejects with error', () => {
  return expect(fetchBadData()).rejects.toThrow('not found');
});
```

### React Component Testing (Testing Library)

```javascript
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import '@testing-library/jest-dom';
import LoginForm from './LoginForm';

test('submits login form', async () => {
  const onSubmit = jest.fn();
  render(<LoginForm onSubmit={onSubmit} />);

  fireEvent.change(screen.getByLabelText('Email'), {
    target: { value: '[email protected]' },
  });
  fireEvent.change(screen.getByLabelText('Password'), {
    target: { value: 'password123' },
  });
  fireEvent.click(screen.getByRole('button', { name: /login/i }));

  await waitFor(() => {
    expect(onSubmit).toHaveBeenCalledWith({
      email: '[email protected]', password: 'password123',
    });
  });
});
```

### Snapshot Testing

```javascript
test('renders correctly', () => {
  const tree = renderer.create(<Button label="Click" />).toJSON();
  expect(tree).toMatchSnapshot();
});
// Update: jest --updateSnapshot
```

### Anti-Patterns

| Bad | Good | Why |
|-----|------|-----|
| `expect(x === y).toBe(true)` | `expect(x).toBe(y)` | Better errors |
| No `await` on async | Always `await` | Swallows failures |
| Snapshot everything | Snapshot UI, assert logic | Snapshot fatigue |

## Quick Reference

| Task | Command |
|------|---------|
| Run all | `npx jest` |
| Watch | `npx jest --watch` |
| Coverage | `npx jest --coverage` |
| Update snapshots | `npx jest --updateSnapshot` |
| Run file | `npx jest tests/calc.test.js` |
| Single test | `test.only('name', () => {})` |

## Deep Patterns

For production-grade patterns, see `reference/playbook.md`:

| Section | What's Inside |
|---------|--------------|
| §1 Production Config | Node + React configs, path aliases, coverage thresholds |
| §2 Mocking Deep Dive | Module/partial/manual mocks, spies, timers, env vars |
| §3 Async Patterns | Promises, rejections, event emitters, streams |
| §4 test.each | Array, tagged template, describe.each for table-driven tests |
| §5 Custom Matchers | toBeWithinRange, toBeValidEmail, TypeScript declarations |
| §6 React Testing Library | userEvent, hooks, context providers |
| §7 Snapshot Testing | Component, inline, property matchers |
| §8 API Service Testing | Mocked axios, CRUD patterns, error handling |
| §9 Global Setup | Multi-project config, DB setup/teardown |
| §10 CI/CD | GitHub Actions with coverage gates |
| §11 Debugging Table | 10 common problems with fixes |
| §12 Best Practices | 15-item production checklist |

© TestMu AI · MIT · LambdaTest/agent-skills

Similar skills

All skills for Testing and QA →

From the same set47

The whole set →
vitest-skill Generates Vitest unit tests for JavaScript and TypeScript projects. Provides patterns for vi mocking and React component testing. CX Codex +1 506installs appium-skill Writes Appium mobile automation scripts for Android and iOS, running on a local emulator or on real devices in the TestMu AI cloud. CX Codex +1 445installs pytest-skill An agent skill that writes pytest tests for Python: fixtures, parametrize, markers, mocking and conftest patterns. Useful when you need test coverage without writing boilerplate by hand. CX Codex +1 442installs selenium-skill Generates production-grade Selenium WebDriver tests across six programming languages. Useful for local test suites or cloud execution on TestMu AI. CX Codex +1 333installs cicd-pipeline-skill cicd-pipeline-skill generates CI/CD configs for test automation: GitHub Actions, Jenkins, GitLab CI, Azure DevOps. Includes TestMu AI cloud integration. CX Codex +1 290installs junit-5-skill Generates production-grade JUnit 5 unit tests for Java with assertions, parameterized tests, Mockito mocks, and nested test groups. Use it to quickly cover your Java code with tests. CX Codex +1 289installs phpunit-skill This skill generates PHPUnit tests for PHP code, including assertions, data providers, mocks, and test doubles. Use it when you need tests shaped around a class or service. CX Codex +1 287installs cucumber-skill Creates Gherkin feature files and matching step definitions. Use it to turn application behavior into Cucumber BDD scenarios. CX Codex +1 283installs

Project sponsors

Companies that keep this analytics open