Skip to content

Commit 47ddb0a

Browse files
test: enhance util.inspect assertions
1 parent 9c90de2 commit 47ddb0a

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

lib/internal/util/inspect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ function getPrefix(constructor, tag, fallback, size = '') {
782782

783783
let result = `${constructor}${size} `;
784784
if (tag !== '') {
785-
const position = constructor.indexOf(tag);
785+
const position = constructor.indexOf(tag);
786786
if (position === -1) {
787787
result += `[${tag}] `;
788788
} else {

test/parallel/test-util-inspect.js

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,8 +1484,8 @@ if (typeof Symbol !== 'undefined') {
14841484
class ObjectSubclass {}
14851485
class ArraySubclass extends Array {}
14861486
class SetSubclass extends Set {}
1487-
class SubclassMap extends Map {}
1488-
class APromiseSubclass extends Promise {}
1487+
class MapSubclass extends Map {}
1488+
class PromiseSubclass extends Promise {}
14891489
class SymbolNameClass {
14901490
static name = Symbol('name');
14911491
}
@@ -1497,11 +1497,11 @@ if (typeof Symbol !== 'undefined') {
14971497
assert.strictEqual(util.inspect(new ArraySubclass(1, 2, 3)),
14981498
'ArraySubclass(3) [ 1, 2, 3 ]');
14991499
assert.strictEqual(util.inspect(new SetSubclass([1, 2, 3])),
1500-
'SetSubclass(3) { 1, 2, 3 }');
1501-
assert.strictEqual(util.inspect(new SubclassMap([['foo', 42]])),
1502-
"SubclassMap(1) { 'foo' => 42 }");
1503-
assert.strictEqual(util.inspect(new APromiseSubclass(() => {})),
1504-
'APromiseSubclass { <pending> }');
1500+
'SetSubclass(3) [Set] { 1, 2, 3 }');
1501+
assert.strictEqual(util.inspect(new MapSubclass([['foo', 42]])),
1502+
"MapSubclass(1) [Map] { 'foo' => 42 }");
1503+
assert.strictEqual(util.inspect(new PromiseSubclass(() => {})),
1504+
'PromiseSubclass [Promise] { <pending> }');
15051505
assert.strictEqual(util.inspect(new SymbolNameClass()),
15061506
'Symbol(name) {}');
15071507
assert.strictEqual(
@@ -1512,6 +1512,38 @@ if (typeof Symbol !== 'undefined') {
15121512
util.inspect(Object.setPrototypeOf(x, null)),
15131513
'[ObjectSubclass: null prototype] { foo: 42 }'
15141514
);
1515+
1516+
class CustomClass {}
1517+
Object.defineProperty(CustomClass.prototype, Symbol.toStringTag, {
1518+
value: 'Custom',
1519+
configurable: true
1520+
});
1521+
assert.strictEqual(util.inspect(new CustomClass()),
1522+
'CustomClass [Custom] {}');
1523+
1524+
class MapClass extends Map {}
1525+
Object.defineProperty(MapClass.prototype, Symbol.toStringTag, {
1526+
value: 'Map',
1527+
configurable: true
1528+
});
1529+
assert.strictEqual(util.inspect(new MapClass([['key', 'value']])),
1530+
"MapClass(1) [Map] { 'key' => 'value' }");
1531+
1532+
class FooSet extends Set {}
1533+
Object.defineProperty(FooSet.prototype, Symbol.toStringTag, {
1534+
value: 'Set',
1535+
configurable: true
1536+
});
1537+
assert.strictEqual(util.inspect(new FooSet([1, 2, 3])),
1538+
'FooSet(3) { 1, 2, 3 }');
1539+
1540+
class Settings extends Set {}
1541+
Object.defineProperty(Settings.prototype, Symbol.toStringTag, {
1542+
value: 'Set',
1543+
configurable: true
1544+
});
1545+
assert.strictEqual(util.inspect(new Settings([1, 2, 3])),
1546+
'Settings(3) [Set] { 1, 2, 3 }');
15151547
}
15161548

15171549
// Empty and circular before depth.

0 commit comments

Comments
 (0)