Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format chai.js exceptions so to display a better diff #386

Closed
vcarel opened this issue Aug 12, 2015 · 6 comments
Closed

Format chai.js exceptions so to display a better diff #386

vcarel opened this issue Aug 12, 2015 · 6 comments
Milestone

Comments

@vcarel
Copy link

vcarel commented Aug 12, 2015

I'm using chai.js to make assertions. Unfortunately, when I compare arrays, I have a poor result because Cucumber doesn't format Chai exceptions like other test runners such as mocha.js or wallaby.js.

For instance, when I compare two big arrays:

actual_content.should.deep.equal(expected_content);

I get:

  AssertionError: expected [ Array(2) ] to deeply equal [ Array(2) ]
    at Assertion.assertEqual (/my_project/node_modules/chai/lib/chai/core/assertions.js:464:19)
    at Assertion.ctx.(anonymous function) [as equal] (/my_project/node_modules/chai/lib/chai/utils/addMethod.js:40:25)
    ...

Mocha, in this case would produce something like:

  AssertionError: expected [ 1, 2 ] to equal [ 3, 4 ]
  + expected - actual

   [
  -  1
  -  2
  +  3
  +  4
   ]

  at Context.<anonymous> (client/test/test_misc.js:20:27)

To be honest, this is annoying for big arrays only, because otherwise Chai produce a better exception message; see issue chaijs/chai#469.

@jbpros
Copy link
Member

jbpros commented Oct 8, 2015

This is an annoying on-purpose issue in Chai. They decided to go for a flexible "DYI" solution with "nice short messages" by default but in the end it makes it pretty cumbersome to output complete error messages. It is particularly difficult to reconstruct the error message with the full array data in it.

#421 is an experimental approach to fix this.

@charlierudolph charlierudolph added this to the 1.2.3 Release milestone Aug 29, 2016
@charlierudolph charlierudolph removed this from the 1.3.0 Release milestone Sep 8, 2016
@charlierudolph charlierudolph added this to the 2.1 Release milestone Sep 21, 2016
@kieranbop
Copy link

hey @charlierudolph , I'm still seeing the same issue as linked above ^^
expected [ Array(9) ] to deeply equal [ Array(9) ]
I've looked through the release you did years back and I can't see anything that would show the diff of two arrays in this case in the output?

@charlierudolph
Copy link
Member

Where exactly are you seeing that message? Most formatters (aside from json / event protocol) should be giving an error message with a diff

@kieranbop
Copy link

I'm seeing it within my cucumber report, or if I wrap the expect in a catch and log out that result.

my step definition function is as follows:

        function() {
            return this.getCurrentPage().getxxxData().getComparisonData()
                .then(expectedText => {
                    return this.getCurrentPage().scrapexxxData()
                        .then(actualText => {
                            return this.expect(expectedText).to.deep.equal(actualText);
                        });
                });
        });

I've tried using the same.members in chai too but they both return back the same result. Any thoughts? or could you point me towards an array comparison in the examples?

@devth
Copy link

devth commented Jan 3, 2018

I'm seeing this too.

@lock
Copy link

lock bot commented Jan 3, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 3, 2019
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

5 participants