-
Notifications
You must be signed in to change notification settings - Fork 1
/
index_test.js
71 lines (61 loc) · 1.89 KB
/
index_test.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import chai from 'chai';
import create from './index';
let assert = chai.assert;
describe('Stack tests', () => {
it('should be properly defined as a function', () => {
assert.isFunction(create);
});
it('should return a function when create is called', () => {
let funcArr = [(data, next)=>{
data.num++;
next(data);
}
, (data, next) => {
data.num++;
next(data);
}
, (data) => {
return new Promise(function (res, rej){
data.num++;
res(data);
});
}];
assert.isFunction(create(funcArr));
});
it('should execute each of an array of functions in order', (done) => {
let funcArr = [(data, next)=>{
assert.strictEqual(data.num, 1);
data.num ++;
assert.strictEqual(data.num, 2);
next(data);
}
, (data, next) => {
data.num = data.num * 3;
assert.strictEqual(data.num, 6);
next(data);
}
, (data, next) => {
return new Promise(function (res, rej){
data.num = data.num / 2;
assert.strictEqual(data.num, 3);
res(data);
});
}]
, run = create(funcArr);
run({num: 1}).then(function (data){
assert.strictEqual(data.num, 3);
done();
}).catch(function (err){
assert.isUndefined(err);
done();
});
});
it('should pass through if no functions', (done) => {
let funcArr
, run = create(funcArr);
run({num: 1}).then(function (data){
assert.isTrue(data.num === 1);
done();
});
});
});