Skip to content

Commit

Permalink
Drop manual newline escapes in favor of inspect in equals
Browse files Browse the repository at this point in the history
  • Loading branch information
mantoni committed Oct 3, 2020
1 parent 86fe254 commit 5bb9567
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
13 changes: 2 additions & 11 deletions lib/assertions/equals.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@

var samsam = require("@sinonjs/samsam");

function escapeNewlines(value) {
if (typeof value === "string") {
return value.replace(/\n/g, "\\n");
}
return value;
}

module.exports = function(referee) {
referee.add("equals", {
// Uses arguments[2] because the function's .length is used to determine
Expand All @@ -22,14 +15,12 @@ module.exports = function(referee) {
return samsam.deepEqual(actual, expected);
},
assertMessage:
"${customMessage}${escapedActual} expected to be equal to ${escapedExpected}",
"${customMessage}${actual} expected to be equal to ${expected}",
refuteMessage:
"${customMessage}${escapedActual} expected not to be equal to ${escapedExpected}",
"${customMessage}${actual} expected not to be equal to ${expected}",
expectation: "toEqual",
values: function(actual, expected, message) {
return {
escapedActual: escapeNewlines(actual),
escapedExpected: escapeNewlines(expected),
actual: actual,
expected: expected,
customMessage: message
Expand Down
4 changes: 2 additions & 2 deletions lib/assertions/equals.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ testHelper.assertionTests("assert", "equals", function(pass, fail, msg, error) {

msg(
"fail for multi-line strings",
"[assert.equals] 'Yo!\\\\nMultiline' expected to be equal to 'Yo!\\\\nHey'",
"[assert.equals] 'Yo!\\nMultiline' expected to be equal to 'Yo!\\nHey'",
"Yo!\nMultiline",
"Yo!\nHey"
);

msg(
"fail for multi-line strings with more than one newline",
"[assert.equals] 'Yo!\\\\nMulti-\\\\nline' expected to be equal to 'Yo!\\\\nHey'",
"[assert.equals] 'Yo!\\nMulti-\\nline' expected to be equal to 'Yo!\\nHey'",
"Yo!\nMulti-\nline",
"Yo!\nHey"
);
Expand Down

0 comments on commit 5bb9567

Please sign in to comment.