spy.calledWithNew
Returns true, when the fake, spy or stub was called the new operator.
js
import tap from "tap";
import * as sinon from "sinon";
tap.test("spy.calledWithNew", (t) => {
const spy = sinon.spy();
t.notOk(
spy.calledWithNew("apple pie"),
"returns false when spy has not been called"
);
new spy("apple pie");
t.ok(
spy.calledWithNew("apple pie"),
"returns true when spy was called with new operator"
);
t.end();
});Resetting calledWithNew to default
You can reset calledWithNew in three different ways:
