plugins/aai-stack-jest/skills/jest-async/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-async/SKILL.md -a claude-code --skill jest-asyncInstallation paths:
.claude/skills/jest-async/# 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