javascript-testing-patterns

Implements unit, integration, and component tests for JavaScript and TypeScript using Jest, Vitest, and Testing Library.

1|Updated Jul 3, 2026
One-click install
npx skills add https://github.com/nejcm/agents --skill javascript-testing-patterns-nejcm
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: javascript-testing-patterns
Source: https://github.com/nejcm/agents/tree/main/skills/javascript-testing-patterns
Command: npx skills add https://github.com/nejcm/agents --skill javascript-testing-patterns-nejcm

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing consistent, maintainable tests for JavaScript and TypeScript code is hard when teams lack established patterns for mocking, async handling, fixtures, and framework configuration, leading to flaky or missing test coverage. ## Core Features & Use Cases - Framework Setup: Ready-to-use Jest and Vitest configurations with coverage thresholds, setup files, and TypeScript support. - Testing Patterns: Concrete examples for pure functions, classes, async services, module mocking, dependency injection, and spying. - Frontend & Integration Testing: React Testing Library guidance, supertest API tests, database integration tests, and faker-based test fixtures. - Use Case: When asked to add tests to an Express API service, apply the dependency injection and mocking patterns to test the service layer in isolation, then use the integration patterns to verify real HTTP endpoints against a test database. ## Quick Start Write unit tests with mocking for my TypeScript UserService class using Vitest.

Frequently Asked Questions about javascript-testing-patterns

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

FAQPage Schema
How do I write unit tests for TypeScript functions with Vitest?▼

Use describe/it blocks with expect assertions from Vitest, organizing tests by function and covering edge cases like zero values and thrown errors. Configure vitest.config.ts with globals, environment, and v8 coverage settings.

Jest vs Vitest: which testing framework should I use?▼

Vitest is faster and integrates natively with Vite-based projects, while Jest offers a mature ecosystem with ts-jest for TypeScript. Both support the same describe/it/expect API, so patterns transfer between them.

How do I mock fetch or external APIs in JavaScript tests?▼

Assign vi.fn() to global.fetch and use mockResolvedValueOnce to simulate responses per test. Verify calls with toHaveBeenCalledWith to assert request URLs, methods, and bodies.

Does Testing Library work with React hooks?▼

Yes, use renderHook combined with act to test custom hooks in isolation. Prefer semantic queries like getByRole and getByPlaceholderText over data-testid when testing rendered components.

Why should I avoid testing implementation details?▼

Testing private functions or internal state makes tests brittle and causes failures during harmless refactors. Test observable behavior and public interfaces instead so tests remain stable as code evolves.