-
Notifications
You must be signed in to change notification settings - Fork 20
/
50-generator-iterator.js
41 lines (32 loc) · 1 KB
/
50-generator-iterator.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
// 50: Generator - iterator
// To do: make all tests pass, leave the assert lines unchanged!
describe('a generator returns an iterable object', function() {
function* generatorFunction(){
yield 1;
yield 2;
}
let generator;
beforeEach(() => {
generator = generatorFunction();
});
it('a generator returns an object', function() {
const typeOfTheGenerator = 'object';
assert.equal(typeof generator, typeOfTheGenerator);
});
it('a generator object has a key `Symbol.iterator`', function() {
const key = Symbol.iterator;
assert.equal(key in generator, true);
});
it('the `Symbol.iterator` is a function', function() {
const theType = typeof generator[Symbol.iterator];
assert.equal(theType, 'function');
});
it('can be looped with `for-of`, which expects an iterable', function() {
function iterateForOf(){
for (let value of generator) {
// no statements needed
}
}
assert.doesNotThrow(iterateForOf);
});
});