-
Notifications
You must be signed in to change notification settings - Fork 0
/
iterator-of-test.js
41 lines (35 loc) · 1.07 KB
/
iterator-of-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
'use strict';
/*eslint-env mocha */
/*eslint max-nested-callbacks: 0 */
var assert = require('assert');
var iteratorOf = require('./iterator-of');
function consume(iterator) {
var results = [];
do {
var result = iterator.next();
results.push(result);
} while (!result.done);
return results;
}
describe('iterator-of:', function() {
it('creates an iterator that can iterate over no arguments', function() {
assert.deepEqual(consume(iteratorOf()), [{value: undefined, done: true}]);
});
it('creates an iterator that can iterate over one argument', function() {
assert.deepEqual(
consume(iteratorOf(1)),
[{value: 1, done: false}, {value: undefined, done: true}]
);
});
it('creates an iterator that can iterate over multiple arguments', function() {
assert.deepEqual(
consume(iteratorOf(1, 2, 3, 4, 5)), [
{value: 1, done: false},
{value: 2, done: false},
{value: 3, done: false},
{value: 4, done: false},
{value: 5, done: false},
{value: undefined, done: true}
]);
});
});