Skip to content

Commit

Permalink
fix: inspect null prototype objects (#57)
Browse files Browse the repository at this point in the history
this previously worked in chai, but not since moving to loupe
  • Loading branch information
philgamevy authored Feb 10, 2022
1 parent 23c7201 commit b4ee644
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 4 additions & 0 deletions test/objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b4ee644

Please sign in to comment.