plugins/aai-stack-jest/skills/jest-patterns/SKILL.md
February 1, 2026
Select agents to install to:
npx add-skill https://github.com/the-answerai/alphaagent-team/blob/main/plugins/aai-stack-jest/skills/jest-patterns/SKILL.md -a claude-code --skill jest-patternsInstallation paths:
.claude/skills/jest-patterns/# Jest Patterns Skill
Testing patterns and best practices for Jest.
## Test Structure
### Describe Blocks
```typescript
describe('UserService', () => {
describe('createUser', () => {
it('should create a user with valid data', async () => {
// test
})
it('should throw error with invalid email', async () => {
// test
})
})
describe('findUser', () => {
it('should return user by id', async () => {
// test
})
it('should return null for non-existent user', async () => {
// test
})
})
})
```
### AAA Pattern
```typescript
it('should calculate total with discount', () => {
// Arrange
const cart = new ShoppingCart()
cart.addItem({ name: 'Widget', price: 100 })
const discount = 0.1
// Act
const total = cart.calculateTotal(discount)
// Assert
expect(total).toBe(90)
})
```
### Setup and Teardown
```typescript
describe('DatabaseService', () => {
let db: Database
let testUser: User
// Before all tests in this describe block
beforeAll(async () => {
db = await Database.connect()
})
// After all tests
afterAll(async () => {
await db.disconnect()
})
// Before each test
beforeEach(async () => {
testUser = await db.createUser({ name: 'Test' })
})
// After each test
afterEach(async () => {
await db.clearTestData()
})
it('should find user', async () => {
const user = await db.findUser(testUser.id)
expect(user).toEqual(testUser)
})
})
```
## Assertions
### Basic Matchers
```typescript
// Equality
expect(value).toBe(exact) // Strict equality (===)
expect(value).toEqual(object) // Deep equality
expect(value).toStrictEqual(object) // Deep equality + undefined properties
// Truthiness
expect(value).toBeTruthy()
expect(value).toBeFalsy()
expect(value).toBeNull()
expect(value).toBeUndefined()
expect(value).toBeDefined()
// Numbers
expect(value).toBeGreaterThan(3)
expect(value).toBeGreaterThanOrEqual(3.5)
expect(value).toBeL