aboutsummaryrefslogtreecommitdiff
path: root/test/js/node/util/node-inspect-tests/parallel/util-inspect-getters-accessing-this.test.js
blob: ab3c17e59cf766318d5d5601e7b1b0603aa4e6ed (plain) (blame)
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
// This test ensures that util.inspect logs getters which access this.

import assert from "assert";
import { inspect } from "util";

test("no assertion failures", () => {
  {
    class X {
      constructor() {
        this._y = 123;
      }

      get y() {
        return this._y;
      }
    }

    const result = inspect(new X(), {
      getters: true,
      showHidden: true,
    });

    assert.strictEqual(result, "X { _y: 123, [y]: [Getter: 123] }");
  }

  // Regression test for https://github.com/nodejs/node/issues/37054
  {
    class A {
      constructor(B) {
        this.B = B;
      }
      get b() {
        return this.B;
      }
    }

    class B {
      constructor() {
        this.A = new A(this);
      }
      get a() {
        return this.A;
      }
    }

    const result = inspect(new B(), {
      depth: 1,
      getters: true,
      showHidden: true,
    });

    assert.strictEqual(
      result,
      "<ref *1> B {\n" +
        "  A: A { B: [Circular *1], [b]: [Getter] [Circular *1] },\n" +
        "  [a]: [Getter] A { B: [Circular *1], [b]: [Getter] [Circular *1] }\n" +
        "}",
    );
  }
});