
Javascript Testing Patterns
Stand up Jest or Vitest suites with mocks, fixtures, and coverage gates so your agent does not ship broken JS/TS.
Overview
JavaScript Testing Patterns is an agent skill most often used in Ship (also Build, Operate) that implements Jest, Vitest, and Testing Library strategies for unit, integration, and end-to-end coverage with mocking and TDD
Install
npx skills add https://github.com/wshobson/agents --skill javascript-testing-patternsWhat is this skill?
- Covers Jest and Vitest setup with TypeScript presets, matchers, and 80% global coverage thresholds
- Unit, integration, and E2E patterns with Testing Library for React/Vue components
- Mocking external APIs, modules, and timers with fixtures and spy patterns
- TDD/BDD workflow hooks and continuous testing in CI/CD pipelines
- Framework comparison guidance when choosing Jest vs Vitest for new repos
- 80% global coverage threshold example for branches, functions, lines, and statements
Adoption & trust: 14.2k installs on skills.sh; 36.5k GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You are shipping JS/TS features without a consistent test stack, so regressions slip through and agents guess at mock and async patterns.
Who is it for?
Solo builders adding or standardizing automated tests on Node, React, or full-stack TypeScript apps before launch.
Skip if: Teams that only need Playwright-only E2E with zero unit layer, or pure Python/Rust repos with no JS test runner.
When should I use this skill?
Writing JavaScript/TypeScript tests, setting up test infrastructure, or implementing TDD/BDD workflows.
What do I get? / Deliverables
You get a configured framework, repeatable test file layouts, and coverage-minded examples your agent can extend on every PR.
- jest.config or vitest config
- Example unit/integration test files
- Coverage threshold settings for CI
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
Shipping safely depends on automated tests; this skill is shelved under Ship because its primary job is test design and CI-ready harnesses before release. Testing subphase is where unit, integration, and E2E patterns live—not ad-hoc debugging in Operate.
Where it fits
Add a minimal Vitest smoke suite to a throwaway prototype before you decide to productionize it.
Structure integration tests around Express or Fastify handlers with mocked databases.
Enforce 80% coverage gates and CI testMatch globs before merging launch-blocking PRs.
Capture a production regression as a failing test, then fix with TDD discipline.
How it compares
Use as a structured testing playbook instead of asking the model to invent Jest config from scratch each session.
Common Questions / FAQ
Who is javascript-testing-patterns for?
Indie and solo developers using Claude Code, Cursor, or Codex who write JavaScript or TypeScript and want agent-guided Jest/Vitest setup and test authoring.
When should I use javascript-testing-patterns?
During Ship when adding CI tests, during Build when scaffolding a new frontend or API, and during Operate when reproducing bugs with regression tests.
Is javascript-testing-patterns safe to install?
Review the Security Audits panel on this Prism page and inspect the skill source in your repo before granting shell or network access in CI.
SKILL.md
READMESKILL.md - Javascript Testing Patterns
# JavaScript Testing Patterns Comprehensive guide for implementing robust testing strategies in JavaScript/TypeScript applications using modern testing frameworks and best practices. ## When to Use This Skill - Setting up test infrastructure for new projects - Writing unit tests for functions and classes - Creating integration tests for APIs and services - Implementing end-to-end tests for user flows - Mocking external dependencies and APIs - Testing React, Vue, or other frontend components - Implementing test-driven development (TDD) - Setting up continuous testing in CI/CD pipelines ## Testing Frameworks ### Jest - Full-Featured Testing Framework **Setup:** ```typescript // jest.config.ts import type { Config } from "jest"; const config: Config = { preset: "ts-jest", testEnvironment: "node", roots: ["<rootDir>/src"], testMatch: ["**/__tests__/**/*.ts", "**/?(*.)+(spec|test).ts"], collectCoverageFrom: [ "src/**/*.ts", "!src/**/*.d.ts", "!src/**/*.interface.ts", ], coverageThreshold: { global: { branches: 80, functions: 80, lines: 80, statements: 80, }, }, setupFilesAfterEnv: ["<rootDir>/src/test/setup.ts"], }; export default config; ``` ### Vitest - Fast, Vite-Native Testing **Setup:** ```typescript // vitest.config.ts import { defineConfig } from "vitest/config"; export default defineConfig({ test: { globals: true, environment: "node", coverage: { provider: "v8", reporter: ["text", "json", "html"], exclude: ["**/*.d.ts", "**/*.config.ts", "**/dist/**"], }, setupFiles: ["./src/test/setup.ts"], }, }); ``` ## Unit Testing Patterns ### Pattern 1: Testing Pure Functions ```typescript // utils/calculator.ts export function add(a: number, b: number): number { return a + b; } export function divide(a: number, b: number): number { if (b === 0) { throw new Error("Division by zero"); } return a / b; } // utils/calculator.test.ts import { describe, it, expect } from "vitest"; import { add, divide } from "./calculator"; describe("Calculator", () => { describe("add", () => { it("should add two positive numbers", () => { expect(add(2, 3)).toBe(5); }); it("should add negative numbers", () => { expect(add(-2, -3)).toBe(-5); }); it("should handle zero", () => { expect(add(0, 5)).toBe(5); expect(add(5, 0)).toBe(5); }); }); describe("divide", () => { it("should divide two numbers", () => { expect(divide(10, 2)).toBe(5); }); it("should handle decimal results", () => { expect(divide(5, 2)).toBe(2.5); }); it("should throw error when dividing by zero", () => { expect(() => divide(10, 0)).toThrow("Division by zero"); }); }); }); ``` ### Pattern 2: Testing Classes ```typescript // services/user.service.ts export class UserService { private users: Map<string, User> = new Map(); create(user: User): User { if (this.users.has(user.id)) { throw new Error("User already exists"); } this.users.set(user.id, user); return user; } findById(id: string): User | undefined { return this.users.get(id); } update(id: string, updates: Partial<User>): User { const user = this.users.get(id); if (!user) { throw new Error("User not found"); } const updated = { ...user, ...updates }; this.users.set(id, updated); return updated; } delete(id: string): boolean { return this.users.delete(id); } } // services/user.service.test.ts import { describe, it, expect, beforeEach } from "vitest"; import { UserServi