问题
When test fails, where I'm comparing two objects using expect(x).to.deep.equal(y)
, I'd like to see the actual values in my browser test report. Instead, I see something like this:
AssertionError: expected { Object (x, y, ...) } to deeply equal { Object (x, y, ...) }
So it doesn't really show anything useful.
Is there a way to customize how chai.js formats these objects?
回答1:
You can now configure the max length before an object gets truncated as per the docs:
chai.config.truncateThreshold = 0; // disable truncating
回答2:
Not really. This is hardcoded into Chai.
The following function is their object formatter (source here), which does exactly what you posted:
} else if (type === '[object Object]') {
var keys = Object.keys(obj)
, kstr = keys.length > 2
? keys.splice(0, 2).join(', ') + ', ...'
: keys.join(', ');
return '{ Object (' + kstr + ') }';
来源:https://stackoverflow.com/questions/19424773/formatting-objects-in-chai-expect-errors