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

how can I know which assertion failed ? #425

Closed
mderazon opened this issue Apr 13, 2015 · 12 comments
Closed

how can I know which assertion failed ? #425

mderazon opened this issue Apr 13, 2015 · 12 comments

Comments

@mderazon
Copy link

Hi guys, don't know if it's a Chai question / Mocha, but I am facing a very basic issue that I feel like i'm missing something.

Some of my tests have more than a few assertions and when some of them fail all I get is something like AssertionError: expected true to be false.

Is there any way to know which assertion failed ? Line number / stack trace perhaps ?

I know I can add a text description to each assertion but I don't want to clutter my test files with unnecessary text just to mark which assertion failed when a line number would be sufficient.

Right now I am just commenting out assertion and re-running tests just to find the faulty one. I feel stupid when I do that...

Thanks 👍

@mderazon
Copy link
Author

possible duplicate of #377

@keithamus
Copy link
Member

Hey @mderazon thanks for the issue.

Mocha should present you with a stack trace of the error, including the line which threw the assertion error.

Could you please paste the output of both your tests, and the failing log - and if it does not give you a stack trace I'll hopefully be able to point you as to why not.

@mderazon
Copy link
Author

Thanks

I actually do see that in some cases Mocha gives me a line number (greyed out below the assertion).
For example when running the assertion

expect(res.body.code).to.equal('something');

I get

AssertionError: expected 'success' to equal 'something'
      + expected - actual

      +"something"
      -"success"

      at Context.<anonymous> (order-test.js:239:30)

But in other cases when I run for example the assertion

expect(res.body.data.user.can_buy).to.be.true;

I simply get

1) should charge successfully


  0 passing (8s)
  1 failing

  1) charge should charge successfully:
     AssertionError: expected false to be true

@keithamus
Copy link
Member

@mderazon what happens if you set chai.config.includeStack = true; at the top of the file?

@mderazon
Copy link
Author

@keithamus it shows the stack!

Is there any reason why this shouldn't be the default behaviour ?

@keithamus
Copy link
Member

Honestly, I don't know. I'm sure there is a good reason. @logicalparadox may be able to tell you.

@diversario
Copy link

I upgraded to chai 2.x and node v0.12.x and now I don't get stack traces anymore, even with chai.config.includeStack = true.

@keithamus
Copy link
Member

@diversario what test runner are you using? What versions? Do you have some sample code? It might be better to file a new issue.

@j13z
Copy link

j13z commented Jun 9, 2015

@diversario: Which mocha version do you use? I figured out that I don’t get proper stack traces anymore for any version > 2.2.1 (thought it was Chai first, but it’s not). See mochajs/mocha#1736

@diversario
Copy link

That might be it; I upgraded to mocha 2.2.5.

@j13z
Copy link

j13z commented Jun 10, 2015

@diversario Try the --full-trace option (see mochajs/mocha#1736, updated).

@meeber
Copy link
Contributor

meeber commented Jun 9, 2016

Seems this has been resolved but let us know if otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants