Debian Codegraph @

packages/babel-plugin-proposal-private-methods/test/fixtures/private-method-loose/context/exec.js

raw
1 class Foo {
2 constructor(status) {
3 this.status = status;
4 expect(() => this.#getStatus = null).toThrow(TypeError);
5 }
6
7 #getStatus() {
8 return this.status;
9 }
10
11 getCurrentStatus() {
12 return this.#getStatus();
13 }
14
15 setCurrentStatus(newStatus) {
16 this.status = newStatus;
17 }
18
19 getFakeStatus(fakeStatus) {
20 const getStatus = this.#getStatus;
21 return function () {
22 return getStatus.call({ status: fakeStatus });
23 };
24 }
25
26 getFakeStatusFunc() {
27 return {
28 status: 'fake-status',
29 getFakeStatus: this.#getStatus,
30 };
31 }
32 }
33
34 const f = new Foo('inactive');
35 expect(f.getCurrentStatus()).toBe('inactive');
36
37 f.setCurrentStatus('new-status');
38 expect(f.getCurrentStatus()).toBe('new-status');
39
40 expect(f.getFakeStatus('fake')()).toBe('fake');
41 expect(f.getFakeStatusFunc().getFakeStatus()).toBe('fake-status');