What problem does it solve?
Building robust JavaScript/TypeScript applications requires comprehensive testing, but setting up effective unit, integration, and end-to-end tests with proper mocking can be complex. This Skill provides a detailed guide to modern testing frameworks and best practices.
Core Features & Use Cases
- Unit Testing: Covers patterns for testing pure functions, classes, and async functions with Jest/Vitest.
- Mocking Strategies: Explains how to mock modules, use dependency injection, and spy on functions.
- Integration Testing: Guides on API and database integration tests using tools like Supertest and
pg.
- Frontend Testing: Provides patterns for testing React components and hooks with Testing Library.
- Use Case: When starting a new Node.js backend or React frontend project, this Skill helps you set up a robust testing infrastructure from scratch, ensuring high code quality and preventing regressions.
Quick Start
Example: Unit test a simple add function
This demonstrates a basic unit test for a pure function using Vitest.
import { describe, it, expect } from 'vitest';
import { add } from './calculator';
describe('Calculator', () => {
describe('add', () => {
it('should add two positive numbers', () => {
expect(add(2, 3)).toBe(5);
});
});
});