-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
err.showDiff = true breaks string diffs #1241
Comments
@felixrabe Did you try the |
I added a bunch of comments that are related to this on #711. |
Here are more details on behalf of @felixrabe: https://gist.github.com/rstacruz/4f7e5c11b5238056cf79 |
Thanks @rstacruz |
@boneskull The thing is that I didn't want inline diffs, I wanted line-by-line diffs. I observed |
Hm, wait, bogus comment, will retest. |
I'm getting this same issue - by default diffs seem to be off, and setting I also noticed that there was a commit related to this (1f9c1bb), so I tried installing mocha from |
It's because Line 182-183 of |
We should have tests asserting diff output using different options. |
String diff were working with an exception from the node Wouldn't if be better to change 1f9c1bb#diff-5c8a5788ecd4b4af2a29bc27ac4ae986R188 to if (err.showDiff !== false ... instead of? if (err.showDiff ... |
Ping. Going to have to go back to Mocha 1.21.4 until this is fixed. |
tried out v2.1.0 & this is still broken |
Show string diff as a raw data, this fix issue mochajs#1241.
fix(reporter/base): string diff - issue #1241
* 'master' of github.com:mochajs/mocha: fix(reporter/base): string diff - issue #1241
Fixed in v2.2.3 |
Is this really fixed? If anything it looks like the specs were changed to expect the wrong thing. Is anyone else still having this issue in 2.2.4? This is my temporary fix... var utils = require('mocha/lib/utils');
var stringify = utils.stringify;
utils.stringify = function (value) {
return typeof value === 'string' ? value : stringify(value);
}; |
yes, you can play it yourself @caseywebdev |
I don't think it's working correctly (v2.2.4). Given this test it('displays line diffs', function () {
var err = new Error('The Error Message');
err.expected = 'foo\nbar\nbuz\nbaz';
err.actual = 'foo\nbar\n';
throw err;
}); the reporter yields
The line diffs are far more useful than the diff of the JSON.stringified string... Running the same test with my patch above yields
|
I don't get what's the problem, you want this string as a "raw data". |
No we dont, we want it back like it was in 1.21. |
Look at the original post by @felixrabe. He clearly wants the line diff because it's far more readable. |
Iet me test 1.2.1
my bad @caseywebdev |
Show string diff as a raw data, this fix issue mochajs#1241.
Show string diff as a raw data, this fix issue mochajs#1241.
For those who come across this issue, it has been fixed, and regression tests exist for the behavior now :) $ cat test.js
it('should compare strings (raw)', function() {
var err = new Error('bad stuff');
err.expected = 'a\nb\nc\nd';
err.actual = 'a\nb\n';
err.showDiff = true;
throw err;
});
it('displays line diffs', function () {
var err = new Error('The Error Message');
err.expected = 'foo\nbar\nbuz\nbaz';
err.actual = 'foo\nbar\n';
throw err;
});
$ mocha --version
2.2.5
$ mocha test.js
1) should compare strings (raw)
2) displays line diffs
0 passing (12ms)
2 failing
1) should compare strings (raw):
Error: bad stuff
+ expected - actual
a
b
+c
+d
at Context.<anonymous> (test.js:2:13)
2) displays line diffs:
Error: The Error Message
+ expected - actual
foo
bar
+buz
+baz
at Context.<anonymous> (test.js:10:13) |
Observed:
Wanted:
Example code: (see https://github.com/felixrabe/mocha-chai-string-diff/blob/master/test/test.js for the complete example code, run with
mocha
)With Chai:
If you uncomment the
// err.showDiff = false;
lines (ie. if you setshowDiff
tofalse
), string diffs show up fine.The text was updated successfully, but these errors were encountered: