blob: 5b51910b3e9157b3d54a50baa12a6e912bd99153 (
plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
test("basic functionality", () => {
class A {
get x() {
return 10;
}
}
expect(A).not.toHaveProperty("x");
expect(new A().x).toBe(10);
});
test("name", () => {
class A {
get x() {}
}
const d = Object.getOwnPropertyDescriptor(A.prototype, "x");
expect(d.get.name).toBe("get x");
});
test("extended name syntax", () => {
const s = Symbol("foo");
class A {
get "method with space"() {
return 1;
}
get 12() {
return 2;
}
get [`he${"llo"}`]() {
return 3;
}
get [s]() {
return 4;
}
}
const a = new A();
expect(a["method with space"]).toBe(1);
expect(a[12]).toBe(2);
expect(a.hello).toBe(3);
expect(a[s]).toBe(4);
});
test("inherited getter", () => {
class Parent {
get x() {
return 3;
}
}
class Child extends Parent {}
expect(Child).not.toHaveProperty("x");
expect(new Child().x).toBe(3);
});
test("inherited getter overriding", () => {
class Parent {
get x() {
return 3;
}
}
class Child extends Parent {
get x() {
return 10;
}
}
expect(new Child().x).toBe(10);
});
|