diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 0e19432a35e117..8cbd6a36227f0f 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -790,6 +790,13 @@ if (typeof Symbol !== 'undefined') { ); } +// Test circular Set +{ + const set = new Set(); + set.add(set); + assert.strictEqual(util.inspect(set), 'Set { [Circular] }'); +} + // test Map { assert.strictEqual(util.inspect(new Map()), 'Map {}'); @@ -801,6 +808,18 @@ if (typeof Symbol !== 'undefined') { 'Map { \'foo\' => null, [size]: 1, bar: 42 }'); } +// Test circular Map +{ + const map = new Map(); + map.set(map, 'map'); + assert.strictEqual(util.inspect(map), "Map { [Circular] => 'map' }"); + map.set(map, map); + assert.strictEqual(util.inspect(map), 'Map { [Circular] => [Circular] }'); + map.delete(map); + map.set('map', map); + assert.strictEqual(util.inspect(map), "Map { 'map' => [Circular] }"); +} + // test Promise { const resolved = Promise.resolve(3);