spy.printf
spy.printf("format string", [arg1, arg2, ...]);
Returns the passed format string with the following replacements performed:
%n- the name of the spy ("spy" by default)
%c- the number of times the spy was called, in words ("once", "twice", etc.)
%C- a list of string representations of the calls to the spy, with each call prefixed by a newline and four spaces
%t- a comma-delimited list of
thisvalues the spy was called on %n- the formatted value of the nth argument passed to
printf %*- a comma-delimited list of the (non-format string) arguments passed to
printf %D- a multi-line list of the arguments received by all calls to the spy
js
import tap from "tap";
import * as sinon from "sinon";
tap.test("spy.printf", (t) => {
const s = sinon.spy(function hello() {
return "world";
});
s();
s();
t.equal(s.printf("%n"), "hello", "formats spy name with %n");
t.equal(
s.printf("The spy %n has been called %c"),
"The spy hello has been called twice",
"formats spy name and call count"
);
t.end();
});