Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! util: add test cases with getters throwing uncommon values
  • Loading branch information
yvele committed Nov 25, 2025
commit 9f8284503727d92d1a6a2610a0cb39925ca02da0
55 changes: 54 additions & 1 deletion test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -2551,7 +2551,38 @@ assert.strictEqual(
"'foobar', { x: 1 } },\n inc: [Getter: NaN]\n}");
}

// Test for property getter throwing an error with a bad message.
// 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)>] }'
);
}

// Property getter throwing an error with message getter that throws.
{
const error = {
// The message itself is a getter that throws
Expand All @@ -2568,6 +2599,28 @@ assert.strictEqual(
);
}

// Property getter throwing an error with a bad message.
{
assert.strictEqual(
inspect({
get foo() { throw new Error(undefined); }
}, { getters: true }),
'{ foo: [Getter: <Inspection threw ()>] }'
);
assert.strictEqual(
inspect({
get foo() { throw new Error(''); }
}, { getters: true }),
'{ foo: [Getter: <Inspection threw ()>] }'
);
assert.strictEqual(
inspect({
get foo() { throw new Error(null); }
}, { getters: true }),
'{ foo: [Getter: <Inspection threw (null)>] }'
);
}

// Check compact number mode.
{
let obj = {
Expand Down