-
Notifications
You must be signed in to change notification settings - Fork 368
/
retry.unit.test.ts
40 lines (38 loc) · 1018 Bytes
/
retry.unit.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { expect, describe, it } from 'vitest';
import { retry } from './retry';
describe('retry', () => {
it('should retry', async () => {
let count = 0;
const result = await retry(
() => {
count++;
if (count < 3) {
throw new Error('my error');
}
return count;
},
{
maxAttempts: 3,
delayMs: () => 0
}
);
expect(result).toEqual(3);
});
it('should throw error after max attempts', async () => {
let count = 0;
try {
await retry(
() => {
count++;
throw new Error('my error');
},
{
maxAttempts: 3,
delayMs: () => 0
}
);
} catch (error: any) {
expect(error.message).toEqual('my error');
}
});
});