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

Include response body to assertion errors #91

Open
ghost opened this issue Mar 26, 2017 · 3 comments
Open

Include response body to assertion errors #91

ghost opened this issue Mar 26, 2017 · 3 comments

Comments

@ghost
Copy link

ghost commented Mar 26, 2017

Hi Daniel,

I think that it might be nice to have an option (or a default) to automatically include responses to assertion error messages. It would make it possible to instantly see what the response actually is instead of going to the test source code and inserting temporary debug output for each failing test.

For now I obtained similar effect by defining

const expect = (value, message) =>
  chakram.expect(value, message || (value && JSON.stringify(value.body, null, 2)))

or

const expect = (value, message) =>
  chakram.expect(value, message || (value && util.inspect(value.body)))

I considered to include entire response object instead of only .body, but the output in this case appears to me to be too verbose.

Thanks

@ghost ghost changed the title Include response body to all assertion errors Include response body to assertion errors Mar 26, 2017
@dareid
Copy link
Owner

dareid commented Apr 9, 2017

Sorry for the late response @a-rodin. Are you aware of the debug functionality available in chakram? The documentation can be seen here : http://dareid.github.io/chakram/jsdoc/module-chakram.html#.startDebug. Does this achieve what you are after?

@ghost
Copy link
Author

ghost commented Apr 9, 2017

Thank you for reply @dareid , I was not aware about this debug functionality. However, because startDebug and stopDebug are not related to chakram.expect, it seems like there is no any straightforward way to print request/response information not for all requests, but only for those with failed assertions.

In my opinion in most cases it is not necessary to print requests and responses for successful tests because it would add unnecessary noise to mocha output, but it is nice to have more information in case of failed assertions out of box. I can draw an analogy between chakram assertions and, for example, expect(one).to.be.deep.equal(another) from chai: the latter doesn't output anything in case of a successful assertion, but prints a detailed object diff if the assertion failed.

@iristich
Copy link

Hi @dareid, are you planning on working on what @a-rodin suggested?

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

2 participants