Use when advanced Jest features including custom matchers, parameterized tests with test.each, coverage configuration, and performance optimization.
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-advanced/SKILL.md -a claude-code --skill jest-advancedInstallation paths:
.claude/skills/jest-advanced/# Jest Advanced
Master advanced Jest features including custom matchers, parameterized tests with test.each, coverage configuration, and performance optimization. This skill covers sophisticated testing techniques for complex scenarios and large test suites.
## Custom Matchers
### Creating Custom Matchers
```javascript
// matchers/toBeWithinRange.js
export function toBeWithinRange(received, floor, ceiling) {
const pass = received >= floor && received <= ceiling;
if (pass) {
return {
message: () =>
`expected ${received} not to be within range ${floor} - ${ceiling}`,
pass: true
};
} else {
return {
message: () =>
`expected ${received} to be within range ${floor} - ${ceiling}`,
pass: false
};
}
}
// jest.setup.js
import { toBeWithinRange } from './matchers/toBeWithinRange';
expect.extend({
toBeWithinRange
});
// test file
describe('Custom matcher', () => {
it('should check if number is within range', () => {
expect(5).toBeWithinRange(1, 10);
expect(15).not.toBeWithinRange(1, 10);
});
});
```
### Async Custom Matcher
```javascript
// matchers/toResolveWithin.js
export async function toResolveWithin(received, timeout) {
const startTime = Date.now();
try {
await received;
const duration = Date.now() - startTime;
const pass = duration <= timeout;
return {
message: () =>
pass
? `expected promise not to resolve within ${timeout}ms (resolved in ${duration}ms)`
: `expected promise to resolve within ${timeout}ms (took ${duration}ms)`,
pass
};
} catch (error) {
return {
message: () => `expected promise to resolve but it rejected with ${error}`,
pass: false
};
}
}
// Usage
expect.extend({ toResolveWithin });
it('should resolve quickly', async () => {
await expect(fetchData()).toResolveWithin(1000);
});
```
### Type-Safe Custom Matchers (TypeScript)
```typescript
// matchers/index.ts
interface CustomMa