Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Ambiguous error message in assert.deepEqual with arrays with custom properties #8956

Closed
lovasoa opened this issue Dec 30, 2014 · 6 comments
Closed

Comments

@lovasoa
Copy link

lovasoa commented Dec 30, 2014

var assert = require("assert");
var m = [1,2];
m.prop = true;
assert.deepEqual([1,2], m);

The assertion fails, as expected. But the error message is: AssertionError: [1,2] deepEqual [1,2].
This is not really helpful, and makes debugging harder.

@cjihrig
Copy link

cjihrig commented Jan 4, 2015

What would you suggest as a better error message?

@lovasoa
Copy link
Author

lovasoa commented Jan 4, 2015

Maybe, if the assertion fails on a custom property in the array, then display the array as an object: AssertionError: [1,2] deepEqual {0:1, 1:2, m:true}.

@cjihrig
Copy link

cjihrig commented Jan 5, 2015

IMO that message is more confusing. It also really complicates the code, which currently relies on a simple JSON.stringify(). I'm -1 on this.

@jfhbrook
Copy link

jfhbrook commented Jan 5, 2015

util.inspect is similarly easy to use and should show custom properties:

> util.inspect(xs)
'[ 1, 2, foo: \'foo\' ]'

@cjihrig
Copy link

cjihrig commented Jan 5, 2015

I've already opened #8734 to switch to util.inspect() for other reasons, so maybe we can kill two birds with one stone if it lands.

@cjihrig
Copy link

cjihrig commented Jan 30, 2015

Closed in bcff90e

@cjihrig cjihrig closed this as completed Jan 30, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants