-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuntil.cycle.js
98 lines (84 loc) · 2.72 KB
/
until.cycle.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
/**
* -----------------------------------------------------------------------------
* VITALS UNIT TESTS: vitals.until.cycle
* -----------------------------------------------------------------------------
* @section base
* @see [vitals.until docs](https://github.com/imaginate/vitals/wiki/vitals.until)
* @see [test api](https://github.com/imaginate/vitals/blob/master/test/setup/interface.js)
* @see [test helpers](https://github.com/imaginate/vitals/blob/master/test/setup/helpers.js)
*
* @author Adam Smith <adam@imaginate.life> (https://github.com/imaginate)
* @copyright 2017 Adam A Smith <adam@imaginate.life> (https://github.com/imaginate)
*
* Annotations:
* @see [JSDoc3](http://usejsdoc.org)
* @see [Closure Compiler JSDoc Syntax](https://developers.google.com/closure/compiler/docs/js-for-compiler)
*/
method('until.cycle', function() {
should('return valid boolean', function() {
test(true, 3, '<iteratee>', function() {
var pass = vitals.until.cycle(true, 3, function(i) {
return i === 1;
});
assert( pass === true );
});
test(true, 3, '<iteratee>', function() {
var fail = vitals.until.cycle(true, 3, function(i) {
return i === 5;
});
assert( fail === false );
});
});
should('call the iteratee x times', function() {
test(true, 3, '<iteratee>', function() {
var keys = [];
vitals.until.cycle(true, 3, function(i) {
keys.push(i);
});
assert( keys[0] === 0 );
assert( keys[1] === 1 );
assert( keys[2] === 2 );
assert( keys.length === 3 );
});
});
should('correctly bind the iteratee', function() {
test(true, 3, '<iteratee>', '<this>', function() {
var cycle = 0;
var self = [];
var fail = vitals.until.cycle(true, 3, function(i) {
this[i] = ++cycle;
}, self);
assert( self[0] === 1 );
assert( self[1] === 2 );
assert( self[2] === 3 );
assert( self.length === 3 );
});
});
should('throw an error', function() {
test(function() {
assert.throws(function() {
vitals.until.cycle();
}, validTypeErr);
});
test(true, function() {
assert.throws(function() {
vitals.until.cycle(true);
}, validTypeErr);
});
test(true, 5, function() {
assert.throws(function() {
vitals.until.cycle(true, 5);
}, validTypeErr);
});
test(true, {}, '<iteratee>', function() {
assert.throws(function() {
vitals.until.cycle(true, {}, function(){});
}, validTypeErr);
});
test(true, 5, '<iteratee>', 'fail', function() {
assert.throws(function() {
vitals.until.cycle(true, 5, function(){}, 'fail');
}, validTypeErr);
});
});
});