Skip to content

Commit

Permalink
Fix inconsistent newline usage %D
Browse files Browse the repository at this point in the history
Update affected unit tests
Add tests for spy.printf %D text replacement
  • Loading branch information
Jay Sherby authored and mroderick committed Mar 12, 2018
1 parent e9aa877 commit f01d847
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 8 deletions.
5 changes: 1 addition & 4 deletions lib/sinon/spy-formatters.js
Expand Up @@ -48,10 +48,7 @@ module.exports = {
for (var i = 0, l = spyInstance.callCount; i < l; ++i) {
// describe multiple calls
if (l > 1) {
if (i > 0) {
message += "\n";
}
message += "Call " + (i + 1) + ":";
message += "\nCall " + (i + 1) + ":";
}
var calledArgs = spyInstance.getCall(i).args;
for (var j = 0; j < calledArgs.length || j < args.length; ++j) {
Expand Down
11 changes: 7 additions & 4 deletions test/assert-test.js
Expand Up @@ -1463,7 +1463,7 @@ describe("assert", function () {
this.obj.doSomething(1, 3, "not");

assert.equals(this.message("calledWith", this.obj.doSomething, 1, 3, "hey").replace(/ at.*/g, ""),
"expected doSomething to be called with arguments " +
"expected doSomething to be called with arguments \n" +
"Call 1:\n" +
color.red("4") + " " + color.green("1") + " \n" +
"3\n" +
Expand Down Expand Up @@ -1652,7 +1652,8 @@ describe("assert", function () {
this.obj.doSomething(1, "hey");

assert.equals(this.message("alwaysCalledWith", this.obj.doSomething, 1, "hey").replace(/ at.*/g, ""),
"expected doSomething to always be called with arguments Call 1:\n" +
"expected doSomething to always be called with arguments \n" +
"Call 1:\n" +
"1\n" +
color.red("3") + " " + color.green("hey") + " \n" +
color.red("hey") + "\n" +
Expand All @@ -1667,7 +1668,8 @@ describe("assert", function () {

assert.equals(
this.message("alwaysCalledWithMatch", this.obj.doSomething, 1, "hey").replace(/ at.*/g, ""),
"expected doSomething to always be called with match Call 1:\n" +
"expected doSomething to always be called with match \n" +
"Call 1:\n" +
"1\n" +
color.red("3") + " " + color.green("hey") + " \n" +
color.red("hey") + "\n" +
Expand All @@ -1691,7 +1693,8 @@ describe("assert", function () {
this.obj.doSomething(1, 3);

assert.equals(this.message("alwaysCalledWithExactly", this.obj.doSomething, 1, 3).replace(/ at.*/g, ""),
"expected doSomething to always be called with exact arguments Call 1:\n" +
"expected doSomething to always be called with exact arguments \n" +
"Call 1:\n" +
"1\n" +
"3\n" +
color.red("hey") + "\n" +
Expand Down
68 changes: 68 additions & 0 deletions test/call-test.js
@@ -1,5 +1,6 @@
"use strict";

var color = require("../lib/sinon/color");
var referee = require("@sinonjs/referee");
var sinonSpyCall = require("../lib/sinon/call");
var sinonSpy = require("../lib/sinon/spy");
Expand Down Expand Up @@ -1430,6 +1431,73 @@ describe("sinonSpy.call", function () {
);
assert.equals(spy.printf("%*", "a", "b", "c"), "a, b, c");
});

describe("arguments", function () {
it("no calls", function () {
var spy = sinonSpy();

assert.equals(spy.printf("%D"), "");
});

it("single call with arguments", function () {
var spy = sinonSpy();

spy(1, "a", true, false, [], {}, null, undefined);

assert.equals(
spy.printf("%D"),
"\n" + color.red("1") +
"\n" + color.red("a") +
"\n" + color.red("true") +
"\n" + color.red("false") +
"\n" + color.red("[]") +
"\n" + color.red("{ }") +
"\n" + color.red("null") +
"\n" + color.red("undefined")
);
});

it("single call without arguments", function () {
var spy = sinonSpy();

spy();

assert.equals(spy.printf("%D"), "");
});

it("multiple calls with arguments", function () {
var spy = sinonSpy();

spy(1, "a", true);
spy(false, [], {});
spy(null, undefined);

assert.equals(
spy.printf("%D"),
"\nCall 1:" +
"\n" + color.red("1") +
"\n" + color.red("a") +
"\n" + color.red("true") +
"\nCall 2:" +
"\n" + color.red("false") +
"\n" + color.red("[]") +
"\n" + color.red("{ }") +
"\nCall 3:" +
"\n" + color.red("null") +
"\n" + color.red("undefined")
);
});

it("multiple calls without arguments", function () {
var spy = sinonSpy();

spy();
spy();
spy();

assert.equals(spy.printf("%D"), "\nCall 1:\nCall 2:\nCall 3:");
});
});
});

it("captures a stack trace", function () {
Expand Down

0 comments on commit f01d847

Please sign in to comment.