-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathasync.test.js
More file actions
37 lines (33 loc) · 894 Bytes
/
async.test.js
File metadata and controls
37 lines (33 loc) · 894 Bytes
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
import { asyncGenerator } from './async';
describe('async generator', () => {
it('auto excute generator', done => {
const asyncFunc = asyncGenerator(function*() {
const a = yield new Promise(resolve => {
setTimeout(() => {
resolve('a');
}, 1000);
});
const b = yield Promise.resolve('b');
const c = yield 'c';
const d = yield Promise.resolve('d');
return [a, b, c, d];
});
asyncFunc().then(res => {
expect(res).toEqual(['a', 'b', 'c', 'd']);
done();
});
});
it('auto excute generator, when throw error', done => {
const errorMsg = 'error';
const asyncFunc = asyncGenerator(function*() {
const s = yield 's';
yield Promise.reject(errorMsg);
return s;
});
asyncFunc()
.catch(res => {
expect(res).toBe(errorMsg);
done();
});
});
});