javascript-testing-patterns

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing reliable JavaScript/TypeScript tests requires knowing framework configuration, mocking strategies, async handling, and component testing patterns, which are scattered across multiple tools and documentation sources. ## 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 unit tests, async functions, class testing, module mocking, dependency injection, spies, API integration tests with supertest, and database integration tests. - Frontend Testing: React component and hook testing with Testing Library, snapshot testing, fixtures with faker, and timer mocking. - Use Case: When building a new Express API, use this Skill to scaffold integration tests that spin up the app, seed a test database, and verify endpoints including authentication flows. ## Quick Start Ask the AI to write Vitest unit tests with mocked fetch calls for your API service module.

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 in TypeScript with Vitest?▼

Configure vitest.config.ts with globals, environment, and coverage settings, then write tests using describe, it, and expect blocks. Follow the AAA pattern (Arrange, Act, Assert) and test both success paths and error cases like thrown exceptions.

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

Vitest offers faster execution and native Vite integration with a Jest-compatible API, making it ideal for Vite-based projects. Jest with ts-jest remains a full-featured choice for established projects; both support coverage thresholds and setup files.

How do I mock fetch or external API calls in tests?▼

Assign vi.fn() to global.fetch and use mockResolvedValueOnce to return fake responses per test. Verify calls with toHaveBeenCalledWith and clear mocks in beforeEach to keep tests isolated.

How do I test React components with Testing Library?▼

Render the component with render(), query elements using semantic queries like getByRole or getByPlaceholderText, and simulate events with fireEvent. Assert on rendered output and callback invocations rather than implementation details.

How do I test code that uses setTimeout or timers?▼

Use vi.useFakeTimers() to replace real timers, then call vi.advanceTimersByTime() to simulate elapsed time deterministically. Restore real timers with vi.useRealTimers() after the test to avoid side effects.

What are the limitations of snapshot testing?▼

Snapshot tests catch unintended UI changes but break on any markup update, creating noisy diffs that reviewers may blindly accept. Use them sparingly for stable components and prefer explicit behavioral assertions for critical logic.