Introduction¶
When writing Jest tests, the common hurdles are not knowing how to use describe / it, but rather how to organize module mocking, async assertions, React component interactions, and snapshots, as well as which patterns can easily lead to false positives. Writing boilerplate and looking up documentation are time-consuming. Below is an introduction to the jest-skill in the LambdaTest agent-skills repository: when Jest, mocking, snapshots, or React testing are mentioned in a conversation, it guides the agent to generate JavaScript / TypeScript test code according to consistent patterns.
What Is This¶
jest-skill is an Agent Skill designed for Jest. Its metadata indicates that it is used for generating Jest unit tests and integration tests, covering mocking, snapshots, async testing, and React Testing Library-based component testing. The maintainer is listed as TestMu AI in the skill metadata; it is licensed under MIT, categorized as unit-testing, and supports JavaScript and TypeScript.
Among the official testing skills from LambdaTest, it directly corresponds to the unit-testing scenario. Jest remains one of the most widely used testing frameworks in the JavaScript ecosystem, and this skill captures common framework patterns into a single reusable document rather than scattered prompts.
Official directory: https://github.com/LambdaTest/agent-skills/tree/main/jest-skill
Core Features¶
The following capabilities are drawn from the Core Patterns and Quick Reference sections of the official skill documentation.
Triggers and Scope
When users mention Jest, describe / it / expect, jest.mock, toMatchSnapshot, snapshot test, JS test, React test, etc., these are appropriate triggers for enabling the skill.
Basic Structure and Assertions
It provides examples of describe / test / beforeEach along with common matchers: toBe, toEqual, toBeTruthy, toMatch, toContain, toHaveLength, toHaveProperty, toMatchObject, toThrow, etc.
Mocking
Includes coverage of jest.fn(), mockReturnValue / mockResolvedValue, module-level jest.mock, factory-based mocks, jest.spyOn, and fake timers via jest.useFakeTimers / advanceTimersByTime.
Async
Provides guidance on async / await testing and demonstrates resolves / rejects assertion syntax.
React Components
The examples use render, screen, fireEvent, and waitFor from @testing-library/react, together with @testing-library/jest-dom, covering a form-filling and submit callback assertion scenario.
Snapshots
Demonstrates toMatchSnapshot() from react-test-renderer; the update command is jest --updateSnapshot.
Anti-Patterns
The documentation uses a table to highlight issues such as avoiding direct boolean assertions like expect(x === y).toBe(true), ensuring proper await for async tests, and preventing snapshot abuse across everything, helping developers avoid false positives.
Advanced Reference
The reference/playbook.md file in the repository lists production-oriented topics (configuration, deep mocking, test.each, custom matchers, advanced RTL usage, API service testing, global setup, CI/CD, troubleshooting tables, practical checklists, etc.); when working on large-scale projects, you can refer to that file, as details beyond those in the Core section are not expanded in the main body.
Installation and Enabling¶
The jest-skill is stored as a generic SKILL.md under the jest-skill directory in the official repository. Add the corresponding directory to the skill loading path of the agent product you are using (specific fields and commands depend on that product’s documentation); this document does not provide differentiated installation commands for Cursor, Codex CLI, or Claude Code, and no speculative steps are provided here.
Source location:
https://github.com/LambdaTest/agent-skills/tree/main/jest-skill
The name field in the skill metadata is jest-skill, and metadata.version is 1.0.
Typical Usage¶
Basic Unit Testing¶
Set up describe and beforeEach, then write test cases for both happy paths and error paths:
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');
});
});
Mock Modules and Spies¶
For external dependencies, use jest.mock; within tests, set mockResolvedValue and assert call arguments:
jest.mock('./database');
const db = require('./database');
db.getUser.mockResolvedValue({ name: 'Alice' });
When observing existing implementations, use jest.spyOn and call mockRestore() after the test.
Async¶
For Promise results, use await or return expect(promise).resolves.toEqual(...); for failure paths, use rejects.toThrow.
React Form Interaction¶
Query elements by label or role, simulate input and click events, and use waitFor to wait for callbacks to be invoked:
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: 'user@test.com' },
});
fireEvent.change(screen.getByLabelText('Password'), {
target: { value: 'password123' },
});
fireEvent.click(screen.getByRole('button', { name: /login/i }));
await waitFor(() => {
expect(onSubmit).toHaveBeenCalledWith({
email: 'user@test.com', password: 'password123',
});
});
});
Common Commands¶
| Task | Command |
|---|---|
| Run all tests | npx jest |
| Watch mode | npx jest --watch |
| Coverage | npx jest --coverage |
| Update snapshots | npx jest --updateSnapshot |
| Specific file | npx jest tests/calc.test.js |
| Debug single test | test.only('name', () => {}) |
Suitable Scenarios and Notes¶
Suitable for
JS/TS projects that already use or plan to use Jest; scenarios where you need to quickly generate test drafts with mocks, async handling, and RTL style; cases where you want the agent’s output to align with idiomatic Jest patterns (matchers, mocking, anti-pattern reminders).
Notes
The skill guides test code patterns but does not replace your project’s actual jest.config, Babel/TS transpilation, or dependency installation; the React examples depend on Testing Library and jest-dom, which need to be configured manually in your project. Snapshots are suitable for UI structure regression, but business logic should still rely primarily on explicit assertions. For production-grade configuration and CI thresholds, refer to reference/playbook.md in the repository.
Conclusion¶
By consolidating mainstream Jest practices (assertions, mocking, async, RTL, snapshots) and common CLI commands into a single skill, jest-skill enables coding agents to consistently produce runnable test skeletons during development conversations. Official URL: https://github.com/LambdaTest/agent-skills/tree/main/jest-skill