-
Notifications
You must be signed in to change notification settings - Fork 0
/
kata.js
44 lines (36 loc) · 1.07 KB
/
kata.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
// 49: Generator - creation
// To do: make all tests pass, leave the assert lines unchanged!
describe('generator can be created in multiple ways', function() {
it('the most common way is by adding `*` after `function`', function() {
function g() {}
assertIsGenerator(g());
});
it('as a function expression, by adding a `*` after `function`', function() {
let g = function() {};
assertIsGenerator(g());
});
it('inside an object by prefixing the function name with `*`', function() {
let obj = {
g() {}
};
assertIsGenerator(obj.g());
});
it('computed generator names, are just prefixed with a `*`', function() {
const generatorName = 'g';
let obj = {
[generatorName]() {}
};
assertIsGenerator(obj.g());
});
it('inside a class the same way', function() {
const generatorName = 'g';
class Klazz {
[generatorName]() {}
}
assertIsGenerator(new Klazz().g());
});
function assertIsGenerator(gen) {
const toStringed = '' + gen;
assert.equal(toStringed, '[object Generator]');
}
});