-
-
Notifications
You must be signed in to change notification settings - Fork 804
/
Copy pathtest.js
123 lines (96 loc) · 2.22 KB
/
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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
'use strict';
// MODULES //
var tape = require( 'tape' );
var noop = require( '@stdlib/utils/noop' );
var funseq = require( './../lib' );
// TESTS //
tape( 'main export is a function', function test( t ) {
t.ok( true, __filename );
t.equal( typeof funseq, 'function', 'main export is a function' );
t.end();
});
tape( 'the function throws an error if not provided multiple functions to execute sequentially', function test( t ) {
t.throws( foo, Error, 'throws an error' );
t.throws( bar, Error, 'throws an error' );
t.end();
function foo() {
funseq();
}
function bar() {
funseq( noop );
}
});
tape( 'the function throws an error if not provided a function', function test( t ) {
var values;
var i;
values = [
'5',
5,
NaN,
null,
undefined,
true,
[],
{}
];
for ( i = 0; i < values.length; i++ ) {
t.throws( badValue1( values[i] ), TypeError, 'throws an error when provided '+values[i] );
t.throws( badValue2( values[i] ), TypeError, 'throws an error when provided '+values[i] );
t.throws( badValue3( values[i] ), TypeError, 'throws an error when provided '+values[i] );
}
t.end();
function badValue1( value ) {
return function badValue() {
funseq( value, noop );
};
}
function badValue2( value ) {
return function badValue() {
funseq( noop, value );
};
}
function badValue3( value ) {
return function badValue() {
funseq( noop, noop, value );
};
}
});
tape( 'the function returns a function', function test( t ) {
var fcn = funseq( noop, noop );
t.strictEqual( typeof fcn, 'function', 'returns a function' );
t.end();
});
tape( 'the function returns a pipeline function', function test( t ) {
var f;
var v;
function a( x ) {
return x * 3;
}
function b( z ) {
return z + 5;
}
function c( r ) {
return r / 10;
}
f = funseq( a, b, c );
v = f( 5 );
t.strictEqual( v, 2, 'returns pipeline result' );
t.end();
});
tape( 'the pipeline function supports providing a leftmost multi-parameter function', function test( t ) {
var f;
var v;
function a( x, y ) {
return x * y;
}
function b( z ) {
return z + 5;
}
function c( r ) {
return r / 10;
}
f = funseq( a, b, c );
v = f( 5, 3 );
t.strictEqual( v, 2, 'returns pipeline result' );
t.end();
});