-
Notifications
You must be signed in to change notification settings - Fork 1
/
promisify.test.ts
57 lines (43 loc) · 1.15 KB
/
promisify.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { promisify } from './promisify';
describe('promisify', () => {
it('promisify api and resolve when succeed', () => {
function api({ success }: any) {
success('success');
}
const promisifyAPI = promisify(api);
expect.assertions(1);
expect(promisifyAPI()).resolves.toEqual('success');
});
it('resolve by success param', async () => {
function api({ success }: any) {
success('success');
}
const promisifyAPI = promisify(api);
const success = jest.fn();
await promisifyAPI({
success,
});
expect(success).toBeCalledTimes(1);
});
it('promisify api and reject when failed', () => {
function api({ fail }: any) {
fail('error');
}
const promisifyAPI = promisify(api);
expect.assertions(1);
expect(promisifyAPI()).rejects.toEqual('error');
});
it('reject by fail param', async () => {
function api({ fail }: any) {
fail('fail');
}
const promisifyAPI = promisify(api);
const fail = jest.fn();
await promisifyAPI({
fail,
}).catch(error => {
expect(error).toBe('fail');
});
expect(fail).toBeCalledTimes(1);
});
});