This repository was archived by the owner on Apr 22, 2023. It is now read-only.
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
assert.equal (and friends) throw incorrect error on circular refs #8696
Closed
Description
When assert.equal
fails, I would expect to get an AssertionError
. Instead, when one of the first two arguments has a circular reference in it, I get a TypeError
. Here is a contrived example from a node#v0.10.33 repl:
> x = {}
{}
> x.x = x
{ x: [Circular] }
> assert.equal(x, {})
TypeError: Converting circular structure to JSON
at Object.stringify (native)
at getMessage (assert.js:75:24)
at new AssertionError (assert.js:45:37)
at fail (assert.js:92:9)
at Function.equal (assert.js:121:27)
at repl:1:9
at REPLServer.self.eval (repl.js:110:21)
at Interface.<anonymous> (repl.js:239:12)
at Interface.emit (events.js:95:17)
at Interface._onLine (readline.js:202:10)
Clearly this is happening because JSON.stringify
fails on x
with its circular references. Maybe something like util.inspect
can be used instead, in order to replace circular references with [Circular]
?
I've tested the following on both 0.10.33 and 0.11.14 and they all behave similarly for the x
defined above.
assert.equal(x, {})
assert.equal({}, x)
assert.deepEqual(x, {})
assert.deepEqual({}, x)
assert.strictEqual(x, {})
assert.strictEqual({}, x)