Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Dec 1, 2024
1 parent d6cff01 commit ad5050d
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions tests/async/timeout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,25 @@ describe('timeout', () => {

vi.advanceTimersToNextTimerAsync()

await expect(promise).rejects.toThrow('timeout')
await expect(promise).rejects.toThrow(_.TimeoutError)
})

test('rejects with a custom error message', async () => {
const promise = _.timeout(10, 'custom error message')
const promise = _.timeout(10, 'too slow')

vi.advanceTimersToNextTimerAsync()

await expect(promise).rejects.toThrow('custom error message')
await expect(promise).rejects.toThrow(new _.TimeoutError('too slow'))
})

test('rejects with a custom error function', async () => {
class CustomError extends Error {
constructor() {
super('custom error function')
}
}
class CustomError extends Error {}

const promise = _.timeout(10, () => new CustomError())

vi.advanceTimersToNextTimerAsync()

await expect(promise).rejects.toThrow(CustomError)
await expect(promise).rejects.toThrow('custom error function')
})

describe('with Promise.race', () => {
Expand Down

0 comments on commit ad5050d

Please sign in to comment.