-
-
Notifications
You must be signed in to change notification settings - Fork 810
/
Copy pathtest.js
44 lines (34 loc) · 975 Bytes
/
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
'use strict';
// MODULES //
var tape = require( 'tape' );
var constantFunction = require( './../lib' );
// TESTS //
tape( 'main export is a function', function test( t ) {
t.ok( true, __filename );
t.equal( typeof constantFunction, 'function', 'main export is a function' );
t.end();
});
tape( 'the function returns a function', function test( t ) {
t.equal( typeof constantFunction(), 'function', 'returns a function' );
t.end();
});
tape( 'the returned function always returns the same value', function test( t ) {
var fcn;
var i;
fcn = constantFunction( 3.14 );
for ( i = 0; i < 100; i++ ) {
t.equal( fcn(), 3.14, 'returns 3.14' );
}
t.end();
});
tape( 'if the value is an object reference, the returned function always returns the same reference', function test( t ) {
var fcn;
var arr;
var i;
arr = [ 1, 2, 3 ];
fcn = constantFunction( arr );
for ( i = 0; i < 100; i++ ) {
t.equal( fcn(), arr, 'returns same reference' );
}
t.end();
});