-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunSync.spec.js
104 lines (75 loc) · 1.92 KB
/
runSync.spec.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
'use strict';
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
const runSync = require('../lib/run-sync').runSync;
chai.use(chaiAsPromised);
const expect = chai.expect;
describe('#runSync', () => {
const createPromise = (param) => {
return () => {
return new Promise(resolve => {
const [nr, stopFor] = param;
setTimeout(() => {
resolve(nr);
}, stopFor);
});
};
};
it('should run in the right order', () => {
// given
const testData = [
[1, 80],
[2, 200],
[3, 10],
[4, 60]
];
const promiseFactoryArr = testData.map(data => {
return createPromise(data);
});
// when
const result = runSync(promiseFactoryArr);
// then
return expect(result).to.eventually.become([1, 2, 3, 4]);
});
it('should return empty array on empty input array', () => {
// given
const emptyArray = [];
// when
const result = runSync(emptyArray);
// then
return expect(result).to.eventually.become([]);
});
it('should return empty array on undefined input array', () => {
// when
const result = runSync();
// then
return expect(result).to.eventually.become([]);
});
xit('should handle promise rejections', () => {
// TODO
});
it('should not fail on non Array input', () => {
// given
const testData = '';
// when
const result = runSync(testData);
// then
return expect(result).to.eventually.become();
});
it('should not fail if last item is undefined', () => {
// given
const testData = [
[1, 80],
[2, 200],
[3, 10],
[undefined, 60]
];
const promiseFactoryArr = testData.map(data => {
return createPromise(data);
});
// when
const result = runSync(promiseFactoryArr);
// then
return expect(result).to.eventually.become([1, 2, 3, undefined]);
});
});