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

jest-async

verified

Jest async testing patterns

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-async/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-async/SKILL.md -a claude-code --skill jest-async

Installation paths:

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

Instructions

# Jest Async Testing Skill

Patterns for testing asynchronous code in Jest.

## Async/Await

### Basic Async Tests

```typescript
// Async function test
test('fetches user data', async () => {
  const user = await fetchUser('1')
  expect(user.name).toBe('John')
})

// Return promise
test('fetches user data', () => {
  return fetchUser('1').then(user => {
    expect(user.name).toBe('John')
  })
})
```

### Async Assertions

```typescript
// Resolves
test('resolves to user', async () => {
  await expect(fetchUser('1')).resolves.toEqual({
    id: '1',
    name: 'John',
  })
})

// Rejects
test('rejects with error', async () => {
  await expect(fetchUser('invalid')).rejects.toThrow('Not found')
})

test('rejects with specific error', async () => {
  await expect(fetchUser('invalid')).rejects.toMatchObject({
    code: 'NOT_FOUND',
    message: 'User not found',
  })
})
```

### Multiple Async Operations

```typescript
test('processes multiple items', async () => {
  const results = await Promise.all([
    processItem('a'),
    processItem('b'),
    processItem('c'),
  ])

  expect(results).toHaveLength(3)
  expect(results.every(r => r.success)).toBe(true)
})

test('handles parallel requests', async () => {
  const [user, posts] = await Promise.all([
    fetchUser('1'),
    fetchPosts('1'),
  ])

  expect(user.id).toBe('1')
  expect(posts).toHaveLength(10)
})
```

## Callbacks

### Done Callback

```typescript
test('calls callback with data', done => {
  function callback(data) {
    try {
      expect(data).toBe('result')
      done()
    } catch (error) {
      done(error)
    }
  }

  fetchDataWithCallback(callback)
})
```

### Converting Callbacks to Promises

```typescript
// Utility for callback-based APIs
function promisify<T>(fn: (callback: (err: Error | null, data: T) => void) => void): Promise<T> {
  return new Promise((resolve, reject) => {
    fn((err, data) => {
      if (err) reject(err)
      else resolve(data)
    })
  })
}

test('converts callback to prom

Validation Details

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