| 1 |
class Base { |
| 2 |
static #foo = 1; |
| 3 |
|
| 4 |
static getThis() { |
| 5 |
return this.#foo; |
| 6 |
} |
| 7 |
|
| 8 |
static updateThis(val) { |
| 9 |
return (this.#foo = val); |
| 10 |
} |
| 11 |
|
| 12 |
static getClass() { |
| 13 |
return Base.#foo; |
| 14 |
} |
| 15 |
|
| 16 |
static updateClass(val) { |
| 17 |
return (Base.#foo = val); |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
class Sub1 extends Base { |
| 22 |
static #foo = 2; |
| 23 |
|
| 24 |
static update(val) { |
| 25 |
return (this.#foo = val); |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
class Sub2 extends Base {} |
| 30 |
|
| 31 |
expect(Base.getThis()).toBe(1); |
| 32 |
expect(Base.getClass()).toBe(1); |
| 33 |
expect(() => Sub1.getThis()).toThrow(); |
| 34 |
expect(Sub1.getClass()).toBe(1); |
| 35 |
expect(() => Sub2.getThis()).toThrow(); |
| 36 |
expect(Sub2.getClass()).toBe(1); |
| 37 |
|
| 38 |
expect(Sub1.update(3)).toBe(3); |
| 39 |
expect(Base.getThis()).toBe(1); |
| 40 |
expect(Base.getClass()).toBe(1); |
| 41 |
expect(() => Sub1.getThis()).toThrow(); |
| 42 |
expect(Sub1.getClass()).toBe(1); |
| 43 |
expect(() => Sub2.getThis()).toThrow(); |
| 44 |
expect(Sub2.getClass()).toBe(1); |
| 45 |
|
| 46 |
expect(Base.updateThis(4)).toBe(4); |
| 47 |
expect(Base.getThis()).toBe(4); |
| 48 |
expect(Base.getClass()).toBe(4); |
| 49 |
expect(() => Sub1.getThis()).toThrow(); |
| 50 |
expect(Sub1.getClass()).toBe(4); |
| 51 |
expect(() => Sub2.getThis()).toThrow(); |
| 52 |
expect(Sub2.getClass()).toBe(4); |
| 53 |
|
| 54 |
expect(Base.updateClass(5)).toBe(5); |
| 55 |
expect(Base.getThis()).toBe(5); |
| 56 |
expect(Base.getClass()).toBe(5); |
| 57 |
expect(() => Sub1.getThis()).toThrow(); |
| 58 |
expect(Sub1.getClass()).toBe(5); |
| 59 |
expect(() => Sub2.getThis()).toThrow(); |
| 60 |
expect(Sub2.getClass()).toBe(5); |
| 61 |
|
| 62 |
expect(() => Sub2.updateThis(6)).toThrow(); |
| 63 |
expect(Sub2.updateClass(7)).toBe(7); |
| 64 |
expect(Base.getThis()).toBe(7); |
| 65 |
expect(Base.getClass()).toBe(7); |
| 66 |
expect(() => Sub1.getThis()).toThrow(); |
| 67 |
expect(Sub1.getClass()).toBe(7); |
| 68 |
expect(() => Sub2.getThis()).toThrow(); |
| 69 |
expect(Sub2.getClass()).toBe(7); |