Automated summary
Generates Jest unit tests for JavaScript/TypeScript code, including React components, with mocks, spies, and describe-block structure.
Strengths
- Covers core Jest patterns: module mocks, spies, fake timers, async tests, and common matchers
- Enforces a clear test file naming convention that mirrors the source tree
- Provides an Arrange/Act/Assert template with mock cleanup in beforeEach/afterEach
- Includes React component testing examples with @testing-library
Limitations
- The Quality Checklist section is truncated in the provided file
- Run commands favor bun, which may not match a project set up with npm or yarn
- Does not cover initial Jest configuration or coverage thresholds
Use it when you need to create or extend Jest tests for an existing JS/TS module or React component.
Skip it if the project uses Vitest, Mocha, or Playwright instead of Jest, since the patterns and API differ.
Security analysis
CautionThe skill is a straightforward Jest test-generation guide. It does not contain destructive commands, credential/token exfiltration, obfuscated payloads (curl|sh, base64), or attempts to disable safety controls. Its only elevated risk comes from the declared Bash/Write/Edit tools, which are used legitimately to create test files and run test commands — standard, powerful-but-expected capabilities for a coding skill, hence 'caution' rather than 'safe' or 'risky'.
- •Declares Bash along with Write/Edit, allowing the agent to execute commands and modify files in the repo (used here for running test suites)
- •Suggests running `bun test` / `npm test`, which executes project-defined scripts that may have side effects
Examples
Write Jest unit tests for src/utils/validator.ts, covering the happy path, edge cases, and error handling, with mocks where needed.Generate a Jest test file for src/components/Button.tsx using @testing-library/react and verify the onClick handler fires.Add missing Jest test coverage to src/models/User.ts, including async methods and error cases with proper mocking.name: jest-generator description: Generate Jest unit tests for JavaScript/TypeScript with mocking, coverage. Use for JS/TS modules, React components, test generation, or encountering missing coverage, improper mocking, test structure errors. allowed-tools: Read, Write, Edit, Bash, Grep, Glob
Jest Generator Skill
Purpose
Generate Jest-based unit tests for JavaScript and TypeScript code, following Jest conventions and best practices with proper mocking, describe blocks, and code organization.
When to Use
- Generate Jest tests for JavaScript/TypeScript modules
- Create test files for React components
- Add missing test coverage to existing code
- Need Jest-specific patterns (mocks, spies, snapshots)
Test File Naming
Source to Test Mapping:
src/components/Feature.tsx→src/components/Feature.test.tsxsrc/utils/validator.ts→src/utils/validator.test.tssrc/models/User.ts→src/models/User.test.ts
Running Tests
# Preferred: Using bun (faster)
bun test
# Run specific file
bun test src/utils/validator.test.ts
# Run with coverage
bun test --coverage
# Watch mode
bun test --watch
# Alternative: Using npm
npm test
npm test -- --coverage
Jest Test Structure
import { functionToTest, ClassToTest } from './Feature'
jest.mock('./dependency')
describe('ModuleName', () => {
beforeEach(() => {
jest.clearAllMocks()
})
afterEach(() => {
jest.restoreAllMocks()
})
describe('ClassName', () => {
let instance: ClassToTest
beforeEach(() => {
instance = new ClassToTest()
})
it('should return expected result with valid input', () => {
// Arrange
const input = { key: 'value' }
const expected = { processed: true }
// Act
const result = instance.method(input)
// Assert
expect(result).toEqual(expected)
})
it('should throw error with invalid input', () => {
expect(() => instance.method(null)).toThrow('Invalid input')
})
})
})
Jest-Specific Patterns
Mocking
// Mock entire module
jest.mock('./api', () => ({
fetchData: jest.fn(),
}))
// Mock with implementation
const mockFn = jest.fn((x: number) => x * 2)
// Spy on method
const spy = jest.spyOn(obj, 'method').mockReturnValue('mocked')
spy.mockRestore()
Async Testing
it('should resolve with data', async () => {
const result = await asyncFunction()
expect(result).toBeDefined()
})
it('should reject with error', async () => {
await expect(asyncFunction()).rejects.toThrow('Error')
})
Timers
beforeEach(() => jest.useFakeTimers())
afterEach(() => jest.useRealTimers())
it('should execute after timeout', () => {
const callback = jest.fn()
setTimeout(callback, 1000)
jest.advanceTimersByTime(1000)
expect(callback).toHaveBeenCalled()
})
Common Matchers
// Equality
expect(value).toBe(expected)
expect(value).toEqual(expected)
// Truthiness
expect(value).toBeTruthy()
expect(value).toBeNull()
expect(value).toBeDefined()
// Arrays/Objects
expect(array).toContain(item)
expect(obj).toHaveProperty('key')
// Functions/Promises
expect(fn).toThrow('error')
await expect(promise).resolves.toBe(value)
// Mock functions
expect(mockFn).toHaveBeenCalled()
expect(mockFn).toHaveBeenCalledWith(arg)
React Component Testing
import { render, screen, fireEvent } from '@testing-library/react'
import '@testing-library/jest-dom'
import { Button } from './Button'
describe('Button', () => {
it('should call onClick when clicked', () => {
const handleClick = jest.fn()
render(<Button onClick={handleClick}>Click me</Button>)
fireEvent.click(screen.getByText('Click me'))
expect(handleClick).toHaveBeenCalledTimes(1)
})
})
Quality Checklist
- [ ] Test file properly named (
<module>.test.ts) - [ ] All exported functions/classes tested
- [ ] Happy path and edge cases included
- [ ] Error conditions tested
- [ ] External dependencies mocked
- [ ] Tests organized with describe blocks
- [ ] beforeEach/afterEach for setup/cleanup
- [ ] Descriptive test names
- [ ] Coverage ≥ 80%
Best Practices
- Use descriptive test names:
should <expected> when <condition> - Organize with describe blocks
- Mock external dependencies only
- Test user behavior for components
- Use test.each for parametrized tests
- Keep tests independent
- Test error conditions
- Aim for 80%+ coverage
From the file to a first result
The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.
View the source and supporting filesThis download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.
1. Download the file
Download SKILL.mdFrom the root of a test project, save the file as .skill-downloads/jest-generator-mrx3xxtk/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.
Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.
mkdir -p '.skill-downloads/jest-generator-mrx3xxtk' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/jest-generator-mrx3xxtk/download' --output '.skill-downloads/jest-generator-mrx3xxtk/SKILL.md.part' && mv '.skill-downloads/jest-generator-mrx3xxtk/SKILL.md.part' '.skill-downloads/jest-generator-mrx3xxtk/SKILL.md'2. Check prerequisites
Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.
Tools declared by the author (check availability in your agent): Read, Write, Edit, Bash, Grep, Glob
No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.
The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.
3. Load the skill
After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.
Claude Code
test -f '.skill-downloads/jest-generator-mrx3xxtk/SKILL.md' && test -s '.skill-downloads/jest-generator-mrx3xxtk/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/jest-generator' && cp -R '.skill-downloads/jest-generator-mrx3xxtk' '.claude/skills/jest-generator'OpenSkills
OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.
Official OpenSkills installationopenskills install './.skill-downloads/jest-generator-mrx3xxtk'openskills read 'jest-generator-mrx3xxtk'Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.
For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.
openskills syncManual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.
4. Try a first task
Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:
Read .skill-downloads/jest-generator-mrx3xxtk/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.
ClickHouse Performance Comparison
Testing
Evaluate ClickHouse performance test results, check PR performance changes, compare with history, and assess whether a result is actionable.
Analyze CI Performance Reports
Testing
Analyze CI performance comparison reports for a ClickHouse PR. Cross-references master history to distinguish real regressions from flaky tests.
Santa Method
Testing
Multi-agent adversarial verification with two independent reviewers. Output is checked twice and iteratively fixed until both pass before shipping.