-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathindex.js
47 lines (42 loc) · 1.27 KB
/
index.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
var expect = require('chai').expect;
var chapter = require('chapter').resolved;
describe(`[${chapter.toUpperCase()}] Check points`, ()=> {
it('Variant define using `var`', ()=> {
expect(function() {
var str = 'test';
var x, y, num = 3 + 2 - 5;
return [str, x, y, num].join();
}()).to.equal("test,,,0");
});
it('Variant define in `for (var .. in ..`', ()=> {
expect(function(n) {
for (var n in {n}); // object equal `{n: "outer"}`
return n;
}("outer")).to.not.equal("outer");
});
it('Variant define in `for (let .. in ..`', ()=> {
expect(function(i) {
var catched = [];
for (let i,j,k=0; k<100; k++) catched = [i, j, k];
return [typeof i, typeof j, typeof k].concat(catched).join();
}("outer")).to.equal("string,undefined,undefined,,,99");
});
it('Variant define by named function', ()=> {
expect(function() {
function foo() {
str = 'test';
}
return foo
}()).to.be.a("function").and.satisfy(x=>x.name=="foo");
});
it('Variant define in catch block only', ()=> {
expect(function() {
try {
throw typeof e; // is undefined
}
catch (e) {
return e; // string "undeifned" as exception object
}
}()).to.equal("undefined");
});
});