/
exec.js
45 lines (37 loc) 路 1.08 KB
/
exec.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
class Foo {
constructor() {
this.x = 1;
this.self = this;
}
m() { return this.x; };
getSelf() { return this }
test() {
const Foo = this;
const o = { Foo: Foo };
const deep = { very: { o } };
function fn() {
return o;
}
function fnDeep() {
return deep;
}
expect((Foo?.["m"])()).toEqual(1);
expect((Foo?.["m"])().toString).toEqual(1..toString);
expect((Foo?.["m"])().toString()).toEqual('1');
expect((o?.Foo.m)()).toEqual(1);
expect((o?.Foo.m)().toString).toEqual(1..toString);
expect((o?.Foo.m)().toString()).toEqual('1');
expect((((o.Foo?.self.getSelf)())?.m)()).toEqual(1);
expect((((o.Foo.self?.getSelf)())?.m)()).toEqual(1);
}
testNull() {
const o = null;
expect(() => { (o?.Foo.m)() }).toThrow();
expect(() => { (o?.Foo.m)().toString }).toThrow();
expect(() => { (o?.Foo.m)().toString() }).toThrow();
expect(() => { (((o.Foo?.self.getSelf)())?.m)() }).toThrow();
expect(() => { (((o.Foo.self?.getSelf)())?.m)() }).toThrow();
}
}
(new Foo).test();
(new Foo).testNull();