jest-patterns

Automate standardized Jest and Vitest testing patterns for JavaScript and TypeScript projects.

39|6|Updated Feb 9, 2026
One-click install
npx skills add https://github.com/vladkesler/initrunner --skill jest-patterns-vladkesler
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: jest-patterns
Source: https://github.com/vladkesler/initrunner/tree/main/examples/roles/unit-tester/skills/jest-patterns
Command: npx skills add https://github.com/vladkesler/initrunner --skill jest-patterns-vladkesler

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Jest and Vitest testing patterns that standardize how you write tests in JavaScript and TypeScript, improving consistency and reliability.

Core Features & Use Cases

  • Structured test organization using describe blocks to group features and behaviors.
  • Use it/test blocks for individual cases, with nested describes for sub-scenarios; includes guidance on setup/teardown via beforeEach/afterEach and beforeAll/afterAll.
  • Guidance on common matchers like toBe, toEqual, toMatchObject, toThrow, toHaveBeenCalledWith, toMatchSnapshot, toContain, and toHaveLength.
  • Mocking strategies with jest.fn/vi.fn, jest.mock/vi.mock, and jest.spyOn/vi.spyOn; how to mock modules and APIs safely.
  • Async testing patterns using async/await and .resolves/.rejects; best practices to ensure proper assertions.
  • How to run tests with npx jest or npx vitest and how to structure test suites for JS/TS projects.
  • Must avoid real API calls and promote isolated tests.

Quick Start

Create a test file using describe blocks for features, write it blocks for scenarios, and configure your environment to run Jest or Vitest in your project.

Frequently Asked Questions about jest-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure Jest and Vitest tests for JavaScript and TypeScript?

Structure Jest and Vitest tests using describe blocks to group features and it blocks for scenarios, nesting describes for sub-scenarios with setup and teardown via beforeEach and afterEach. This standardizes test organization and improves consistency across JS and TS projects.

What is the best way to mock modules and APIs in Jest and Vitest?

Mock modules and APIs in Jest and Vitest using jest.fn or vi.fn for functions, jest.mock or vi.mock for modules, and jest.spyOn or vi.spyOn for spies. This strategy ensures tests remain isolated and avoids real API calls to maintain reliability.

How do I test asynchronous code with async/await in Jest and Vitest?

Test asynchronous code in Jest and Vitest using async and await within it blocks, or apply .resolves and .rejects matchers to promises. These async testing patterns ensure proper assertions are made before the test completes.

Does this testing pattern work for both unit and integration tests in TypeScript?

Yes, these Jest and Vitest testing patterns apply to unit and integration tests across JavaScript and TypeScript apps. They define expectations for test structure, mocking strategy, async handling, and recommended matchers suitable for both test types.

What matchers should I use for snapshot and equality testing in Vitest?

Use common matchers like toBe and toEqual for equality, toMatchObject for partial object matching, toMatchSnapshot for snapshots, and toHaveBeenCalledWith for mock verification. These matchers standardize expectations in Vitest and Jest test suites.

Why should unit tests avoid real API calls in Jest and Vitest?

Unit tests must avoid real API calls in Jest and Vitest to promote isolated tests and prevent external dependencies from causing flaky results. Use mocking strategies like jest.mock or vi.mock to safely simulate API responses instead.