Help us improve
Share bugs, ideas, or general feedback.
From jest-generator
Generates Jest unit tests for JavaScript/TypeScript modules and React components with mocking, coverage, spies, and snapshots. Use for test creation, missing coverage, or improper mocking.
npx claudepluginhub secondsky/claude-skills --plugin jest-generatorHow this skill is triggered — by the user, by Claude, or both
Slash command
/jest-generator:jest-generatorThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
Generate Jest-based unit tests for JavaScript and TypeScript code, following Jest conventions and best practices with proper mocking, describe blocks, and code organization.
Provides Jest testing patterns for unit tests, mocks, spies, snapshots, setup/teardown, and matchers including equality, truthiness, numbers, strings, and arrays.
Generates unit tests matching project patterns and frameworks like Jest/Vitest (JS/TS), pytest (Python), Go testing, JUnit (Java), RSpec (Ruby).
Generates unit tests for Python (pytest), JavaScript/TypeScript (Jest), Java (JUnit), Go code with coverage focus, edge cases, mocks, and fixtures.
Share bugs, ideas, or general feedback.
Generate Jest-based unit tests for JavaScript and TypeScript code, following Jest conventions and best practices with proper mocking, describe blocks, and code organization.
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# 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
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')
})
})
})
// 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()
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')
})
beforeEach(() => jest.useFakeTimers())
afterEach(() => jest.useRealTimers())
it('should execute after timeout', () => {
const callback = jest.fn()
setTimeout(callback, 1000)
jest.advanceTimersByTime(1000)
expect(callback).toHaveBeenCalled()
})
// 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)
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)
})
})
<module>.test.ts)should <expected> when <condition>