Here's a simple Mocha test case. It emulates chai.js's expect(a).eq(b)
behavior.
it('comparing strings', function () {
var string1 = "div, p {\n color: red;\n margin: 0;\n padding: 0;\n}";
var string2 = "div, p {\n color: red;\n margin: 20px;\n padding: 0;\n}";
var e = new Error("Strings don't match");
e.expected = string1;
e.actual = string2;
e.showDiff = true;
throw e;
});
Doing mocha
on this yields:
$ mocha -C
...
1) comparing strings:
Error: Strings don't match
+ expected - actual
+"div, p {\n color: red;\n margin: 0;\n padding: 0;\n}"
-"div, p {\n color: red;\n margin: 20px;\n padding: 0;\n}"
Doing mocha --inline-diffs
yields the exact same thing:
$ mocha -C
...
1) comparing strings:
Error: Strings don't match
+ expected - actual
+"div, p {\n color: red;\n margin: 0;\n padding: 0;\n}"
-"div, p {\n color: red;\n margin: 20px;\n padding: 0;\n}"
If we remove err.showDiffs
here, here's what we get, which is the expected behavior. (Strange how the diff shows up with showDiffs off!)
$ mocha -C
...
1) comparing strings:
Error: Strings don't match
+ expected - actual
div, p {
color: red;
+ margin: 0;
- margin: 20px;
padding: 0;
}
here's a link back to the issue