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

Preserve custom messages in diff output #949

Closed

Conversation

bajtos
Copy link

@bajtos bajtos commented Aug 13, 2013

When the developer adds extra information to assertion, e.g.

expect('actual', 'description').to.equal('expected'); // Chai style

this extra message ('description') is preserved in the output
even in case when Mocha overwrites the original assertion message with
a string diff.

See also chaijs/chai#189.

When the developer adds extra information to assertion, e.g.

   expect('actual', 'description').to.equal('expected'); // Chai style

this extra message ('description') is preserved in the output
even in case when Mocha overwrites the original assertion message with
a string diff.
@logicalparadox
Copy link

I'm not sure of what discussion has gone into this but I feel that if we continue to just add properties to AssertionError eventually it will be chaos. For Chai, I don't want to have to worry about properties for different test frameworks to accomplish a given thing.

As such I have started a discussion on what "extras" AssertionError could use and hopefully put together some sort of loose standard that Chai can follow. You can view the discussion at chaijs/assertion-error#1 and I would appreciate any feedback.

@visionmedia I would be particularly interested in your thoughts on the topic. Much thanks!

@bajtos
Copy link
Author

bajtos commented Aug 13, 2013

@logicalparadox Thanks for a quick reply!

Frankly, there was no discussion about this change so far. I was confused when I found that mocha is swallowing my assert message in certain cases and decided to go ahead and submit a fix. Let's start the discussion now!

To give more context on my problem:

expect(undefined, 'first name').to.equal('expected');
/* result:
AssertionError: first name: expected undefined to equal 'expected'
*/

expect('actual', 'surname').to.equal('expected');
/* result:
actual expected
"expectedactual"
*/

Maybe I was wrong by changing both Mocha and Chai. Perhaps it's enough to fix Mocha so that it always prints the AssertionError message?

What's your opinion, @visionmedia?

@jonahkagan
Copy link

I also was surprised to not see a custom message for a failed assert.equal. A workaround I have been using is to translate assert.equal(x, y, message) into assert(x == y, msg).

@hallas
Copy link

hallas commented Sep 9, 2013

@logicalparadox whats your opinion now?

@travisjeffery
Copy link
Contributor

issue looks dead, not a fan how this is tacked on AssertionError either

@bajtos
Copy link
Author

bajtos commented Dec 9, 2013

@travisjeffery Thank you for your comment. The issue seemed to look dead because we were waiting for an opinion from Mocha maintainers.

I filled a proper bug #1065, so that we can discuss the right problem, which is the bug in mocha and not the fix presented here.

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

Successfully merging this pull request may close these issues.

5 participants