Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inconsistent newline usage %D #1732

Merged
merged 1 commit into from
Mar 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 1 addition & 4 deletions lib/sinon/spy-formatters.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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