From b4ee644cedc7d394d979d043da568a999c8a59b1 Mon Sep 17 00:00:00 2001 From: philgamevy <44057119+philgamevy@users.noreply.github.com> Date: Thu, 10 Feb 2022 15:11:11 +0000 Subject: [PATCH] fix: inspect null prototype objects (#57) this previously worked in chai, but not since moving to loupe --- index.js | 5 +++++ test/objects.js | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/index.js b/index.js index 0a27ca8..0f289f8 100644 --- a/index.js +++ b/index.js @@ -165,6 +165,11 @@ export function inspect(value, options) { return inspectObject(value, options) } + // last chance to check if it's an object + if (value === Object(value)) { + return inspectObject(value, options) + } + // We have run out of options! Just stringify the value return options.stylize(String(value), type) } diff --git a/test/objects.js b/test/objects.js index deda334..880f584 100644 --- a/test/objects.js +++ b/test/objects.js @@ -39,6 +39,10 @@ for (const [suite, inspect] of Object.entries({ expect(inspect(Object.create({ a: 1 }))).to.equal('{}') }) + it('returns `{}` for empty objects with a null prototype', () => { + expect(inspect(Object.create(Object.create(null)))).to.equal('{}') + }) + it("shows objects' own properties for objects with an anonoymous prototype", () => { const obj = Object.create({ a: 1 }) obj.b = 2