Use when jest testing patterns including unit tests, mocks, spies, snapshots, and assertion techniques for comprehensive test coverage.
View on GitHubTheBushidoCollective/han
jutsu-jest
January 24, 2026
Select agents to install to:
npx add-skill https://github.com/TheBushidoCollective/han/blob/main/jutsu/jutsu-jest/skills/jest-testing-patterns/SKILL.md -a claude-code --skill jest-testing-patternsInstallation paths:
.claude/skills/jest-testing-patterns/# Jest Testing Patterns
Master Jest testing patterns including unit tests, mocks, spies, snapshots, and assertion techniques for comprehensive test coverage. This skill covers the fundamental patterns and practices for writing effective, maintainable tests using Jest.
## Basic Test Structure
### Test Suite Organization
```javascript
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);
});
});
describe('subtract', () => {
it('should subtract two numbers', () => {
expect(subtract(5, 3)).toBe(2);
});
});
});
```
### Setup and Teardown
```javascript
describe('Database operations', () => {
let db;
// Runs once before all tests in this describe block
beforeAll(async () => {
db = await initializeDatabase();
});
// Runs once after all tests in this describe block
afterAll(async () => {
await db.close();
});
// Runs before each test
beforeEach(() => {
db.clear();
});
// Runs after each test
afterEach(() => {
db.resetMocks();
});
it('should insert a record', async () => {
const result = await db.insert({ name: 'John' });
expect(result.id).toBeDefined();
});
it('should find a record', async () => {
await db.insert({ id: 1, name: 'John' });
const result = await db.findById(1);
expect(result.name).toBe('John');
});
});
```
## Matchers and Assertions
### Common Matchers
```javascript
describe('Matchers', () => {
it('should test equality', () => {
expect(2 + 2).toBe(4); // Strict equality
expect({ a: 1 }).toEqual({ a: 1 }); // Deep equality
expect([1, 2, 3]).toStrictEqual([1, 2, 3]); // Strict deep equality
});
it('should test truthiness', () => {
expect(true).toBeTruthy();
expect(false).toBeFa