From 26b715ec753f08b23fc1c63fc544890f1510f2e9 Mon Sep 17 00:00:00 2001 From: Josh Greenberger Date: Wed, 7 Dec 2016 15:03:29 -0800 Subject: [PATCH] fix test, add dependencies, and simplify logic to format simple diffs --- lib/sinon/assert.js | 5 +++++ lib/sinon/spy.js | 9 ++------- package.json | 2 ++ test/assert-test.js | 18 +++++++++--------- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/lib/sinon/assert.js b/lib/sinon/assert.js index 4a8815c5f..759ba89f6 100644 --- a/lib/sinon/assert.js +++ b/lib/sinon/assert.js @@ -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") { diff --git a/lib/sinon/spy.js b/lib/sinon/spy.js index 7599d4b0a..3f5fcefcd 100644 --- a/lib/sinon/spy.js +++ b/lib/sinon/spy.js @@ -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]; @@ -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; }); diff --git a/package.json b/package.json index e086a0767..53588d79d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/assert-test.js b/test/assert-test.js index 8ea28c912..673ecd99d 100644 --- a/test/assert-test.js +++ b/test/assert-test.js @@ -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 () { @@ -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 + " "); }); @@ -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 () { @@ -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 () { @@ -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 () {