jest-generator

jest-generator is a skill for Claude Code from matteocervelli/llms. It costs 32 tokens per session (4,018 once invoked), scanned A, original, MIT.

A guide for generating unit tests with Jest for JavaScript and TypeScript code. Jest is a testing framework that runs small, focused checks on code.

In plain words
What is it for?
It is for testing functions, classes, services, and components while following common Jest file and test-structure conventions.
Why use it?
It helps create consistent tests with mocks, spies, snapshots, and coverage for modules and React components.

Skill for Claude Code

Written for Claude Code: allowed-tools in frontmatter.

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/matteocervelli/llms/jest-generator
Any agent
npx skills add matteocervelli/llms --skill jest-generator
Clone the repo
git clone --depth 1 https://github.com/matteocervelli/llms

Made for: Claude Code.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for jest-generator

README.md
[![agentmods](https://agentmods.dev/badge/skills/matteocervelli/llms/jest-generator.svg)](https://agentmods.dev/skills/matteocervelli/llms/jest-generator)
Your own site
<a href="https://agentmods.dev/skills/matteocervelli/llms/jest-generator"><img src="https://agentmods.dev/badge/skills/matteocervelli/llms/jest-generator.svg" alt="Measured on agentmods" height="20"></a>
Per session 32 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 4,018 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00032 $0.04018
Opus 5 $0.00016 $0.02009
Sonnet 5 $0.00006 $0.00804
Haiku 4.5 $0.00003 $0.00402

Measured 4d ago against content hash 5e5110e8bf1d, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

jest-generator scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.archive/claude-v1/skills/jest-generator/SKILL.md · 741 lines

How it starts

The opening of the file, as written. The whole thing — 741 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Jest Generator Skill

Purpose

This skill generates Jest-based unit tests for JavaScript and TypeScript code, following Jest conventions, best practices, and project standards. It creates comprehensive test suites 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 JS/TS code
  • Need Jest-specific patterns (mocks, spies, snapshots)

Test File Naming Convention

Source to Test Mapping:

  • Source: src/components/Feature.tsx
  • Test: src/components/Feature.test.tsx
  • Pattern: <source_filename>.test.ts or <source_filename>.test.js

Examples:

  • src/utils/validator.tssrc/utils/validator.test.ts
  • src/models/User.tssrc/models/User.test.ts
  • src/services/api.jssrc/services/api.test.js
  • src/components/Button.tsxsrc/components/Button.test.tsx

Jest Test Generation Workflow

1. Analyze JavaScript/TypeScript Source Code

Read the source file:

# Read the source to understand structure
cat src/components/Feature.tsx

Identify test targets:

  • Exported functions to test
  • Classes and methods
  • React components (if applicable)
  • Error conditions
  • Edge cases
  • Dependencies and imports

Output: List of functions/classes/components requiring tests


2. Generate Test File Structure

Create test file with proper naming:

/**
 * Unit tests for [module name]
 *
 * Tests cover:
 * - [Functionality 1]
 * - [Functionality 2]
 * - Error handling and edge cases
 */

import { functionToTest, ClassToTest, ComponentToTest } from './Feature';
import { mockDependency } from './__mocks__/dependency';

// Mock external dependencies
jest.mock('./dependency');
jest.mock('external-library');

// ============================================================================
// Test Setup
// ============================================================================

describe('ModuleName', () => {
  // Setup before each test
  beforeEach(() => {
    jest.clearAllMocks();
  });

  // Cleanup after each test
  afterEach(() => {
    jest.restoreAllMocks();
  });

  // ========================================================================
  // Class Tests
  // ========================================================================

  describe('ClassName', () => {
    let instance: ClassToTest;

    beforeEach(() => {
      instance = new ClassToTest();
    });

    describe('constructor', () => {
      it('should initialize with valid parameters', () => {
        // Arrange & Act
        const instance = new ClassToTest({ param: 'value' });

        // Assert
        expect(instance.param).toBe('value');
        expect(instance.initialized).toBe(true);
      });

      it('should throw error with invalid parameters', () => {
        // Arrange
        const invalidParams = null;

        // Act & Assert
        expect(() => new ClassToTest(invalidParams)).toThrow('Invalid parameters');
      });
    });

    describe('method', () => {
      it('should return expected result with valid input', () => {
        // Arrange
        const input = { name: 'test', value: 123 };

        // Act
        const result = instance.method(input);

        // Assert
        expect(result.processed).toBe(true);
        expect(result.name).toBe('test');
        expect(result.value).toBe(123);
      });

      it('should throw error with invalid input', () => {
        // Arrange
        const invalidInput = null;

        // Act & Assert
        expect(() => instance.method(invalidInput)).toThrow('Invalid input');
      });

      it('should handle edge case with empty input', () => {
        // Arrange
        const emptyInput = {};

        // Act
        const result = instance.method(emptyInput);

        // Assert
        expect(result).toEqual({});
      });
    });
  });

  // ========================================================================
  // Function Tests
  // ========================================================================

  describe('functionToTest', () => {
    it('should return expected result with valid input', () => {
      // Arrange
      const input = { key: 'value' };
      const expected = { processed: true, key: 'value' };

      // Act
      const result = functionToTest(input);

      // Assert
      expect(result).toEqual(expected);
    });

    it('should handle null input', () => {
      // Arrange
      const input = null;

      // Act & Assert
      expect(() => functionToTest(input)).toThrow('Input cannot be null');
    });

    it('should handle undefined input', () => {
      // Arrange
      const input = undefined;

      // Act
      const result = functionToTest(input);

      // Assert
      expect(result).toBeUndefined();
    });
  });

  // ========================================================================
  // Tests with Mocks
  // ========================================================================

  describe('functionWithDependency', () => {
    it('should call dependency with correct parameters', () => {
      // Arrange
      const input = { key: 'value' };
      const mockDep = jest.fn().mockReturnValue({ status: 'success' });

      // Act
      const result = functionWithDependency(input, mockDep);

      // Assert
      expect(mockDep).toHaveBeenCalledWith(input);
      expect(mockDep).toHaveBeenCalledTimes(1);
      expect(result.status).toBe('success');
    });

    it('should handle dependency error', () => {
      // Arrange
      const input = { key: 'value' };
      const mockDep = jest.fn().mockRejectedValue(new Error('API error'));

      // Act & Assert
      await expect(functionWithDependency(input, mockDep))
        .rejects.toThrow('API error');
    });
  });

  // ========================================================================
  // Async Tests
  // ========================================================================

  describe('asyncFunction', () => {
    it('should resolve with expected result', async () => {
      // Arrange
      const input = { key: 'value' };

      // Act
      const result = await asyncFunction(input);

      // Assert
      expect(result.success).toBe(true);
      expect(result.data).toEqual(input);
    });

    it('should reject with error on failure', async () => {
      // Arrange
      const invalidInput = null;

      // Act & Assert
      await expect(asyncFunction(invalidInput))
        .rejects.toThrow('Invalid input');
    });

    it('should handle timeout', async () => {
      // Arrange
      jest.useFakeTimers();
      const promise = asyncFunctionWithTimeout();

      // Act
      jest.advanceTimersByTime(5000);

      // Assert
      await expect(promise).rejects.toThrow('Timeout');
      jest.useRealTimers();
    });
  });

  // ========================================================================
  // Parametrized Tests (using test.each)
  // ========================================================================

  describe('validation', () => {
    it.each([
      ['[email protected]', true],
      ['invalid.email', false],
      ['', false],
      [null, false],
      ['@no-user.com', false],
    ])('should validate email "%s" as %s', (email, expected) => {
      // Act
      const result = validateEmail(email);

      // Assert
      expect(result).toBe(expected);
    });
  });

  describe('permissions', () => {
    it.each([
      ['admin', 'all'],
      ['moderator', 'edit'],
      ['user', 'read'],
      ['guest', 'none'],
    ])('should return "%s" permission for %s user', (userType, expected) => {
      // Arrange
      const user = { type: userType };

      // Act
      const result = getPermissions(user);

      // Assert
      expect(result).toBe(expected);
    });
  });
});

Read the full file on GitHub · 741 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 741 lines · 32 tokens per session scan A 5e5110e8bf1d

Subscribe to this mod's changes

jest-generator is a skill published in the GitHub repository matteocervelli/llms (25 stars, last pushed 3mo ago), licensed MIT. It adds 32 tokens to every session and 4,018 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-01.