Repository: nodejs/node
File: test/parallel/test-util-inspect.js (JavaScript)

Code before:
    '{ foo: \u001b[36m[Getter:\u001b[39m ' +
      '\u001b[33m1\u001b[39m\u001b[36m]\u001b[39m }');
  assert.strictEqual(
    inspect(thrower, { getters: true }),
    '{ foo: [Getter: <Inspection threw (Oops)>] }');
  assert.strictEqual(
    inspect(getset, { getters: true }),
    '{ foo: [Getter/Setter: 1], inc: [Getter: 2] }');
  assert.strictEqual(
    inspect(getset, { getters: 'get' }),
    '{ foo: [Getter/Setter], inc: [Getter: 3] }');
  assert.strictEqual(
    inspect(getset, { getters: 'set' }),
    '{ foo: [Getter/Setter: 3], inc: [Getter] }');
  getset.foo = new Set([[{ a: true }, 2, {}], 'foobar', { x: 1 }]);
  assert.strictEqual(
    inspect(getset, { getters: true }),
    '{\n  foo: [Getter/Setter] Set(3) { [ [Object], 2, {} ], ' +
      "'foobar', { x: 1 } },\n  inc: [Getter: NaN]\n}");
}

// Property getter throwing throwing uncommon values.
{
  assert.strictEqual(
    inspect({
      /* eslint-disable-next-line no-throw-literal */
      get foo() { throw null; }
    }, { getters: true }),
    '{ foo: [Getter: <Inspection threw>] }'
  );
  assert.strictEqual(
    inspect({
      /* eslint-disable-next-line no-throw-literal */
      get foo() { throw true; }
    }, { getters: true }),
    '{ foo: [Getter: <Inspection threw (undefined)>] }'
  );
  assert.strictEqual(
    inspect({
      /* eslint-disable-next-line no-throw-literal */
      get foo() { throw {}; }
    }, { getters: true }),
    '{ foo: [Getter: <Inspection threw (undefined)>] }'
  );
  assert.strictEqual(
    inspect({
      get foo() { throw Error; }
    }, { getters: true }),
    '{ foo: [Getter: <Inspection threw (undefined)>] }'
  );
}

Review comment (suggestion):
```suggestion
      // eslint-disable-next-line no-throw-literal
```

Code after:
    inspect(get, { getters: true, colors: true }),
    '{ foo: \u001b[36m[Getter:\u001b[39m ' +
      '\u001b[33m1\u001b[39m\u001b[36m]\u001b[39m }');
  assert.strictEqual(
    inspect(getset, { getters: true }),
    '{ foo: [Getter/Setter: 1], inc: [Getter: 2] }');
  assert.strictEqual(
    inspect(getset, { getters: 'get' }),
    '{ foo: [Getter/Setter], inc: [Getter: 3] }');
  assert.strictEqual(
    inspect(getset, { getters: 'set' }),
    '{ foo: [Getter/Setter: 3], inc: [Getter] }');
  getset.foo = new Set([[{ a: true }, 2, {}], 'foobar', { x: 1 }]);
  assert.strictEqual(
    inspect(getset, { getters: true }),
    '{\n  foo: [Getter/Setter] Set(3) { [ [Object], 2, {} ], ' +
      "'foobar', { x: 1 } },\n  inc: [Getter: NaN]\n}");
}

// Property getter throwing an error.
{
  const error = new Error('Oops');
  error.stack = [
    'Error: Oops',
    '    at get foo (/foo/node_modules/foo.js:2:7)',
    '    at get bar (/foo/node_modules/bar.js:827:30)',
  ].join('\n');

  const thrower = {
    get foo() { throw error; }
  };

  assert.strictEqual(
    inspect(thrower, { getters: true }),
    '{\n' +
    '  foo: [Getter: <Inspection threw (Error: Oops\n' +
    '      at get foo (/foo/node_modules/foo.js:2:7)\n' +
    '      at get bar (/foo/node_modules/bar.js:827:30))>]\n' +
    '}',
  );
};

// Property getter throwing an error with getters that throws.
// https://github.com/nodejs/node/issues/60683
{
  const badError = new Error();

  const innerError = new Error('Oops');
  innerError.stack = [
    'Error: Oops',
    '    at get foo (/foo/node_modules/foo.js:2:7)',