_Promise

说明

模拟实现 ES6Promise

源码

用法

_Promise.test.ts
1
describe('ES6Achieve._Promise tests', () => {
2
const _Promise = ES6Achieve._Promise;
3
4
test('_Promise should work fine', () => {
5
const result1 = new _Promise((resolve) => {
6
setTimeout(() => {
7
resolve(1);
8
}, 0);
9
});
10
result1.then((value) => {
11
expect(value).toBe(1);
12
13
return value + 1;
14
}).then((value) => {
15
expect(value).toBe(2);
16
});
17
18
const result2 = new _Promise((resolve) => {
19
resolve(100);
20
});
21
result2.then((value) => {
22
expect(value).toBe(100);
23
24
return value / 5;
25
}).then((value) => {
26
expect(value).toBe(20);
27
});
28
});
29
});
Copied!
最近更新 11mo ago
复制链接