/
lib.js
43 lines (41 loc) · 957 Bytes
/
lib.js
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
import 'should';
import co from 'co';
import { lib } from '../..';
const { Array: { prototype: { forEach, map } } } = lib;
describe('Array.prototype.forEach', () => {
it('should work', () => {
const input = [4, 0, 1];
const expected = input;
const actual = [];
return co(function *() {
yield* input::forEach(function *(value) {
yield new Promise((fulfill) => {
setTimeout(() => {
actual.push(value);
fulfill();
}, value * 10);
});
});
}).then(() => {
actual.should.eql(expected);
});
});
});
describe('Array.prototype.map', () => {
it('should work', () => {
const input = [4, 0, 1];
const expected = [8, 0, 2];
let actual;
return co(function *() {
actual = yield* input::map(function *(value) {
return yield new Promise((fulfill) => {
setTimeout(() => {
fulfill(value * 2);
}, value * 10);
});
});
}).then(() => {
actual.should.eql(expected);
});
});
});