Claude Skills
CollectionsCompareWorkflowsNominate
Sign inSign up
© 2026 Curated Agent Skills·Learn more about Agent Skills
Back to repository

jest-patterns

verified

Jest testing patterns and best practices

View on GitHub

Marketplace

alphaagent-team

the-answerai/alphaagent-team

Plugin

aai-stack-jest

stack

Repository

the-answerai/alphaagent-team

plugins/aai-stack-jest/skills/jest-patterns/SKILL.md

Last Verified

February 1, 2026

Install Skill

Select agents to install to:

Scope:
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-patterns

Installation paths:

Claude
.claude/skills/jest-patterns/
Powered by add-skill CLI

Instructions

# 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

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
6667 chars