Skip to content

Commit ffe75c6

Browse files
committed
fixup! util: improve test readability with an array
1 parent 1144617 commit ffe75c6

File tree

1 file changed

+49
-46
lines changed

1 file changed

+49
-46
lines changed

test/parallel/test-util-inspect.js

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2783,56 +2783,59 @@ assert.strictEqual(
27832783
}
27842784

27852785
// Property getter throwing uncommon values.
2786-
{
2787-
assert.strictEqual(
2788-
inspect({
2789-
// eslint-disable-next-line no-throw-literal
2790-
get foo() { throw undefined; }
2791-
}, { getters: true }),
2792-
'{ foo: [Getter: <Inspection threw (undefined)>] }'
2793-
);
2794-
assert.strictEqual(
2795-
inspect({
2796-
// eslint-disable-next-line no-throw-literal
2797-
get foo() { throw null; }
2798-
}, { getters: true }),
2799-
'{ foo: [Getter: <Inspection threw (null)>] }'
2800-
);
2801-
assert.strictEqual(
2802-
inspect({
2803-
// eslint-disable-next-line no-throw-literal
2804-
get foo() { throw 'string'; }
2805-
}, { getters: true }),
2806-
"{ foo: [Getter: <Inspection threw ('string')>] }"
2807-
);
2808-
assert.strictEqual(
2809-
inspect({
2810-
// eslint-disable-next-line no-throw-literal
2811-
get foo() { throw true; }
2812-
}, { getters: true }),
2813-
'{ foo: [Getter: <Inspection threw (true)>] }'
2814-
);
2815-
assert.strictEqual(
2816-
inspect({
2817-
// eslint-disable-next-line no-throw-literal
2818-
get foo() { throw {}; }
2819-
}, { getters: true }),
2820-
'{ foo: [Getter: <Inspection threw ({})>] }'
2821-
);
2822-
assert.strictEqual(
2823-
inspect({
2824-
// eslint-disable-next-line no-throw-literal
2825-
get foo() { throw { get message() { return 'Oops'; } }; }
2826-
}, { getters: true }),
2827-
"{ foo: [Getter: <Inspection threw ({ message: [Getter: 'Oops'] })>] }"
2828-
);
2786+
[
2787+
{
2788+
val: undefined,
2789+
expected: '{ foo: [Getter: <Inspection threw (undefined)>] }'
2790+
},
2791+
{
2792+
val: null,
2793+
expected: '{ foo: [Getter: <Inspection threw (null)>] }'
2794+
},
2795+
{
2796+
val: true,
2797+
expected: '{ foo: [Getter: <Inspection threw (true)>] }'
2798+
},
2799+
{
2800+
val: 1,
2801+
expected: '{ foo: [Getter: <Inspection threw (1)>] }'
2802+
},
2803+
{
2804+
val: 1n,
2805+
expected: '{ foo: [Getter: <Inspection threw (1n)>] }'
2806+
},
2807+
{
2808+
val: Symbol(),
2809+
expected: '{ foo: [Getter: <Inspection threw (Symbol())>] }'
2810+
},
2811+
{
2812+
val: () => {},
2813+
expected: '{ foo: [Getter: <Inspection threw ([Function: val])>] }'
2814+
},
2815+
{
2816+
val: 'string',
2817+
expected: "{ foo: [Getter: <Inspection threw ('string')>] }"
2818+
},
2819+
{
2820+
val: [],
2821+
expected: '{ foo: [Getter: <Inspection threw ([])>] }'
2822+
},
2823+
{
2824+
val: { get message() { return 'Oops'; } },
2825+
expected: "{ foo: [Getter: <Inspection threw ({ message: [Getter: 'Oops'] })>] }"
2826+
},
2827+
{
2828+
val: Error,
2829+
expected: '{ foo: [Getter: <Inspection threw ([Function: Error])>] }'
2830+
},
2831+
].forEach(({ val, expected }) => {
28292832
assert.strictEqual(
28302833
inspect({
2831-
get foo() { throw Error; }
2834+
get foo() { throw val; }
28322835
}, { getters: true }),
2833-
'{ foo: [Getter: <Inspection threw ([Function: Error])>] }'
2836+
expected,
28342837
);
2835-
}
2838+
});
28362839

28372840
// Check compact number mode.
28382841
{

0 commit comments

Comments
 (0)