Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting objects in chai.expect errors

Tags:

mocha.js

chai

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?

like image 751
raimohanska Avatar asked Oct 17 '13 10:10

raimohanska


People also ask

Should I assert vs vs expect?

Note expect and should uses chainable language to construct assertions, but they differ in the way an assertion is initially constructed. In the case of should , there are also some caveats and additional tools to overcome the caveats. var expect = require('chai').

What is chai expect?

expect , should = chai. should(); The expect interface provides a function as a starting point for chaining your language assertions. It works on node. js and in all browsers.

What assertion styles are present in Chai testing assertion library?

Chai is such an assertion library, which provides certain interfaces to implement assertions for any JavaScript-based framework. Chai's interfaces are broadly classified into two: TDD styles and BDD styles.

What is chai assertion?

Chai assertion library is an external javascript library used to write assertions. Compared to what we write directly in javascript, this assertion library needs less time & effort and easy use. Chai assertion library is available by default in the Postman.


1 Answers

You can now configure the max length before an object gets truncated as per the docs:

chai.config.truncateThreshold = 0; // disable truncating
like image 60
wolverdude Avatar answered Sep 28 '22 12:09

wolverdude