Skip to content

Commit

Permalink
fix test, add dependencies, and simplify logic to format simple diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
jdgreenberger committed Dec 7, 2016
1 parent 5fc509c commit 26b715e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
5 changes: 5 additions & 0 deletions lib/sinon/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ function mirrorPropAsAssertion(name, method, message) {
var args = slice.call(arguments, 1);
var failed = false;

// Hack to be replaced
if (args[0] && args[0].test) {
message = message.replace("%D", "%*%C");
}

verifyIsValidAssertion(name, args);

if (typeof method === "function") {
Expand Down
9 changes: 2 additions & 7 deletions lib/sinon/spy.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,6 @@ var spyApi = {
var args = slice.call(arguments, 1);
var formatter;

// Hack to be replaced
if (format.includes("%D") && args[0] && args[0].test) {
format = format.replace("%D", "%*%C");
}

return (format || "").replace(/%(.)/g, function (match, specifyer) {
formatter = spyApi.formatters[specifyer];

Expand Down Expand Up @@ -430,8 +425,8 @@ function colorDiffText(diff) {
} else if (part.removed) {
text = text.red;
}
if (!text.includes("\n")) {
text += " "; // format simple types
if (diff.length === 2) {
text += " "; // format simple diffs
}
return text;
});
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"eslint-pre-commit"
],
"dependencies": {
"colors": "^1.1.2",
"diff": "^3.1.0",
"formatio": "1.1.1",
"lolex": "^1.4.0",
"samsam": "^1.1.3",
Expand Down
18 changes: 9 additions & 9 deletions test/assert-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1365,8 +1365,8 @@ describe("assert", function () {
assert.equals(this.message("calledWith", this.obj.doSomething, 1, 3, "hey").replace(/ at.*/g, ""),
"expected doSomething to be called with arguments \n" +
"4".red + " " + "1".green + " \n" +
"3 \n" +
"hey ");
"3\n" +
"hey");
});

it("assert.calledWith exception message with multiple calls", function () {
Expand All @@ -1377,11 +1377,11 @@ describe("assert", function () {
"expected doSomething to be called with arguments " +
"Call 0:\n" +
"4".red + " " + "1".green + " \n" +
"3 \n" +
"hey \n" +
"3\n" +
"hey\n" +
"Call 1:\n" +
"1 \n" +
"3 \n" +
"1\n" +
"3\n" +
"not".red + " " + "hey".green + " ");
});

Expand Down Expand Up @@ -1419,7 +1419,7 @@ describe("assert", function () {
" second: { nest: true },\n" +
" third: [{ fourth: { nest: true } }]\n".red +
" third: [{ fourth: { nest: false } }]\n".green +
"}, \"fifth\"] ");
"}, \"fifth\"]");
});

it("assert.calledWith exception message with a missing argument", function () {
Expand All @@ -1428,7 +1428,7 @@ describe("assert", function () {
assert.equals(this.message("calledWith", this.obj.doSomething, 1, 3).replace(/ at.*/g, ""),
"expected doSomething to be called with arguments \n" +
"4".red + " " + "1".green + " \n" +
"3".green + " ");
"3".green);
});

it("assert.calledWith exception message with an excess argument", function () {
Expand All @@ -1437,7 +1437,7 @@ describe("assert", function () {
assert.equals(this.message("calledWith", this.obj.doSomething, 1).replace(/ at.*/g, ""),
"expected doSomething to be called with arguments \n" +
"4".red + " " + "1".green + " \n" +
"3".red + " ");
"3".red);
});

it("assert.calledWith match.any exception message", function () {
Expand Down

0 comments on commit 26b715e

Please sign in to comment.