/jest-unit
Unit testing skill using Jest for TypeScript and JavaScript, covering mocking, spies, snapshots, coverage, async testing, and custom matchers.
$ npx -y skills add PramodDutta/qaskills --skill jest-unit --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/jest-unit
Context preview
The summary Claude sees to decide when to auto-load this skill.
Unit testing skill using Jest for TypeScript and JavaScript, covering mocking, spies, snapshots, coverage, async testing, and custom matchers.
SKILL.md
jest-unit.SKILL.mdname: jest-unit
description: Unit testing skill using Jest for TypeScript and JavaScript, covering mocking, spies, snapshots, coverage, async testing, and custom matchers.
license: MIT
metadata:
author: thetestingacademy
version: 1.0.0
source: https://qaskills.sh/skills/thetestingacademy/jest-unit
Jest Unit Testing Skill
You are an expert software engineer specializing in unit testing with Jest. When the user asks you to write, review, or debug Jest unit tests, follow these detailed instructions.
Core Principles
1. **Test behavior, not implementation** -- Tests should verify what code does, not how it does it. 2. **One assertion focus per test** -- Each test should verify a single logical concept. 3. **Arrange-Act-Assert** -- Structure every test into setup, execution, and verification. 4. **Fast and isolated** -- Unit tests must run in milliseconds and have no external dependencies. 5. **Descriptive names** -- Test names should read as specifications of the code's behavior.
Project Structure
src/
services/
user.service.ts
user.service.test.ts
order.service.ts
order.service.test.ts
utils/
validators.ts
validators.test.ts
formatters.ts
formatters.test.ts
models/
user.model.ts
__mocks__/
axios.ts
database.ts
__tests__/
integration/
user-order.test.ts
jest.config.tsConfiguration
// jest.config.ts
import type { Config } from 'jest';
const config: Config = {
preset: 'ts-jest',
testEnvironment: 'node',
roots: ['<rootDir>/src'],
testMatch: ['**/*.test.ts', '**/*.spec.ts'],
collectCoverageFrom: [
'src/**/*.ts',
'!src/**/*.d.ts',
'!src/**/*.test.ts',
'!src/**/index.ts',
],
coverageThresholds: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80,
},
},
coverageReporters: ['text', 'lcov', 'json-summary'],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
},
setupFilesAfterSetup: ['<rootDir>/jest.setup.ts'],
clearMocks: true,
restoreMocks: true,
};
export default config;Writing Tests
Basic Test Structure
// validators.ts
export function isValidEmail(email: string): boolean {
const regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return regex.test(email);
}
export function isStrongPassword(password: string): boolean {
return (
password.length >= 8 &&
/[A-Z]/.test(password) &&
/[a-z]/.test(password) &&
/[0-9]/.test(password) &&
/[!@#$%^&*]/.test(password)
);
}// validators.test.ts
import { isValidEmail, isStrongPassword } from './validators';
describe('isValidEmail', () => {
it('should return true for valid email addresses', () => {
expect(isValidEmail('user@example.com')).toBe(true);
expect(isValidEmail('first.last@domain.co.uk')).toBe(true);
expect(isValidEmail('user+tag@example.com')).toBe(true);
});
it('should return false for invalid email addresses', () => {
expect(isValidEmail('')).toBe(false);
expect(isValidEmail('not-an-email')).toBe(false);
expect(isValidEmail('@missing-local.com')).toBe(false);
expect(isValidEmail('missing-at.com')).toBe(false);
expect(isValidEmail('spaces here@bad.com')).toBe(false);
});
});
describe('isStrongPassword', () => {
it('should accept a strong password', () => {
expect(isStrongPassword('SecurePass1!')).toBe(true);
});
it('should reject passwords shorter than 8 characters', () => {
expect(isStrongPassword('Ab1!')).toBe(false);
});
it('should reject passwords without uppercase letters', () => {
expect(isStrongPassword('lowercase1!')).toBe(false);
});
it('should reject passwords without lowercase letters', () => {
expect(isStrongPassword('UPPERCASE1!')).toBe(false);
});
it('should reject passwords without numbers', () => {
expect(isStrongPassword('NoNumbers!')).toBe(false);
});
it('should reject passwords without special characters', () => {
expect(isStrongPassword('NoSpecial1')).toBe(false);
});
});Testing Classes and Services
// user.service.ts
import { UserRepository } from './user.repository';
import { EmailService } from './email.service';
export class UserService {
constructor(
private userRepo: UserRepository,
private emailService: EmailService
) {}
async createUser(email: string, name: string): Promise<User> {
const existing = await this.userRepo.findByEmail(email);
if (existing) {
throw new Error('User already exists');
}
const user = await this.userRepo.create({ email, name });
await this.emailService.sendWelcomeEmail(user.email, user.name);
return user;
}
async getUser(id: string): Promise<User | null> {
return this.userRepo.findById(id);
}
async deleteUser(id: string): Promise<void> {
const user = await this.userRepo.findById(id);
if (!user) {
throw new Error('User not found');
}
await this.userRepo.delete(id);
}
}// user.service.test.ts
import { UserService } from './user.service';
import { UserRepository } from './user.repository';
import { EmailService } from './email.service';
// Mock the dependencies
jest.mock('./user.repository');
jest.mock('./email.service');
describe('UserService', () => {
let userService: UserService;
let mockUserRepo: jest.Mocked<UserRepository>;
let mockEmailService: jest.Mocked<EmailService>;
beforeEach(() => {
mockUserRepo = new UserRepository() as jest.Mocked<UserRepository>;
mockEmailService = new EmailService() as jest.Mocked<EmailService>;
userService = new UserService(mockUserRepo, mockEmailService);
});
describe('createUser', () => {
it('should create a user and send welcome email', async () => {
const newUser = { id: '1', email: 'new@example.com', name: 'New User' };
mockUserRepo.findByEmail.mockResolvedValue(null);
mockUserRepo.create.mockResolvedValue(newUser);Read more
name: jest-unit description: Unit testing skill using Jest for TypeScript and JavaScript, covering mocking, spies, snapshots, coverage, async testing, and custom matchers. license: MIT metadata: author: thetestingacademy version: 1.0.0 source: https://qaskills.sh/skills/thetestingacademy/jest-unit
Jest Unit Testing Skill
You are an expert software engineer specializing in unit testing with Jest. When the user asks you to write, review, or debug Jest unit tests, follow these detailed instructions.
Core Principles
1. **Test behavior, not implementation** -- Tests should verify what code does, not how it does it. 2. **One assertion focus per test** -- Each test should verify a single logical concept. 3. **Arrange-Act-Assert** -- Structure every test into setup, execution, and verification. 4. **Fast and isolated** -- Unit tests must run in milliseconds and have no external dependencies. 5. **Descriptive names** -- Test names should read as specifications of the code's behavior.
Project Structure
src/
services/
user.service.ts
user.service.test.ts
order.service.ts
order.service.test.ts
utils/
validators.ts
validators.test.ts
formatters.ts
formatters.test.ts
models/
user.model.ts
__mocks__/
axios.ts
database.ts
__tests__/
integration/
user-order.test.ts
jest.config.tsConfiguration
// jest.config.ts
import type { Config } from 'jest';
const config: Config = {
preset: 'ts-jest',
testEnvironment: 'node',
roots: ['<rootDir>/src'],
testMatch: ['**/*.test.ts', '**/*.spec.ts'],
collectCoverageFrom: [
'src/**/*.ts',
'!src/**/*.d.ts',
'!src/**/*.test.ts',
'!src/**/index.ts',
],
coverageThresholds: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80,
},
},
coverageReporters: ['text', 'lcov', 'json-summary'],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
},
setupFilesAfterSetup: ['<rootDir>/jest.setup.ts'],
clearMocks: true,
restoreMocks: true,
};
export default config;Writing Tests
Basic Test Structure
// validators.ts
export function isValidEmail(email: string): boolean {
const regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return regex.test(email);
}
export function isStrongPassword(password: string): boolean {
return (
password.length >= 8 &&
/[A-Z]/.test(password) &&
/[a-z]/.test(password) &&
/[0-9]/.test(password) &&
/[!@#$%^&*]/.test(password)
);
}// validators.test.ts
import { isValidEmail, isStrongPassword } from './validators';
describe('isValidEmail', () => {
it('should return true for valid email addresses', () => {
expect(isValidEmail('user@example.com')).toBe(true);
expect(isValidEmail('first.last@domain.co.uk')).toBe(true);
expect(isValidEmail('user+tag@example.com')).toBe(true);
});
it('should return false for invalid email addresses', () => {
expect(isValidEmail('')).toBe(false);
expect(isValidEmail('not-an-email')).toBe(false);
expect(isValidEmail('@missing-local.com')).toBe(false);
expect(isValidEmail('missing-at.com')).toBe(false);
expect(isValidEmail('spaces here@bad.com')).toBe(false);
});
});
describe('isStrongPassword', () => {
it('should accept a strong password', () => {
expect(isStrongPassword('SecurePass1!')).toBe(true);
});
it('should reject passwords shorter than 8 characters', () => {
expect(isStrongPassword('Ab1!')).toBe(false);
});
it('should reject passwords without uppercase letters', () => {
expect(isStrongPassword('lowercase1!')).toBe(false);
});
it('should reject passwords without lowercase letters', () => {
expect(isStrongPassword('UPPERCASE1!')).toBe(false);
});
it('should reject passwords without numbers', () => {
expect(isStrongPassword('NoNumbers!')).toBe(false);
});
it('should reject passwords without special characters', () => {
expect(isStrongPassword('NoSpecial1')).toBe(false);
});
});Testing Classes and Services
// user.service.ts
import { UserRepository } from './user.repository';
import { EmailService } from './email.service';
export class UserService {
constructor(
private userRepo: UserRepository,
private emailService: EmailService
) {}
async createUser(email: string, name: string): Promise<User> {
const existing = await this.userRepo.findByEmail(email);
if (existing) {
throw new Error('User already exists');
}
const user = await this.userRepo.create({ email, name });
await this.emailService.sendWelcomeEmail(user.email, user.name);
return user;
}
async getUser(id: string): Promise<User | null> {
return this.userRepo.findById(id);
}
async deleteUser(id: string): Promise<void> {
const user = await this.userRepo.findById(id);
if (!user) {
throw new Error('User not found');
}
await this.userRepo.delete(id);
}
}// user.service.test.ts
import { UserService } from './user.service';
import { UserRepository } from './user.repository';
import { EmailService } from './email.service';
// Mock the dependencies
jest.mock('./user.repository');
jest.mock('./email.service');
describe('UserService', () => {
let userService: UserService;
let mockUserRepo: jest.Mocked<UserRepository>;
let mockEmailService: jest.Mocked<EmailService>;
beforeEach(() => {
mockUserRepo = new UserRepository() as jest.Mocked<UserRepository>;
mockEmailService = new EmailService() as jest.Mocked<EmailService>;
userService = new UserService(mockUserRepo, mockEmailService);
});
describe('createUser', () => {
it('should create a user and send welcome email', async () => {
const newUser = { id: '1', email: 'new@example.com', name: 'New User' };
mockUserRepo.findByEmail.mockResolvedValue(null);
mockUserRepo.create.mockResolvedValue(newUser);QA Skills Directory QA Skills is a curated directory of testing-specific skills for AI coding agents (Claude Code, Cursor, Copilot, etc.).
Repo: PramodDutta/qaskills
Other skills on qaskills.
- /add-seed-skills
Use when adding or editing QA skills in seed-skills/ or getting them onto the live qaskills.sh catalog, e.g. "add N new skills", "create a seed skill for X", "seed the database", "the skill page is empty", "skill 404s on the site".
Open skill - /publish-seo-batch
Use when publishing SEO blog articles to qaskills.sh, e.g. "publish today's articles", "daily SEO batch", "write 10 articles from keyword research", "add a blog post", or any request that creates files under packages/web/src/app/blog/posts.
Open skill - /ship-prod
Use when deploying qaskills.sh to production, verifying whether a deploy landed, or when a push to main did not show up on the live site, e.g. "deploy", "ship it", "push this live", "is prod updated?", "the site still shows the old version".
Open skill - /api-testing-rest
Comprehensive RESTful API testing patterns covering HTTP methods, status codes, request/response validation, authentication, error handling, and contract testing.
Open skill - /claude-code-qa
The complete QA skill for Claude Code — turn Claude into an expert QA engineer that picks the right test type, writes reliable Playwright, Cypress, and pytest tests, eliminates flaky tests, enforces coverage, and wires up CI. Claude Code QA testing done right.
Open skill - /cypress-e2e
End-to-end testing skill using Cypress for web applications, covering custom commands, network intercepts, fixtures, cy.session, and component testing patterns.
Open skill

