0
sinon spyを関数式にすることは可能ですか?例えば、このコードを見てください。Sinon spy on関数式
function one() { return 1; }
function two() { return 2; }
function three() { return 3; }
function myMethod() {
var n1 = one();
var n2 = two();
var n3 = three();
return n1 + n2 + n3;
}
QUnit.module('My test');
QUnit.test('testing functions', (assert) => {
assert.expect(3);
const spyOne = sinon.spy(one);
const spyTwo = sinon.spy(two);
const spyThree = sinon.spy(three);
\t myMethod();
assert.ok(spyOne.called, "called one");
assert.ok(spyTwo.called, "called two");
assert.ok(spyThree.called, "called three");
sinon.restore();
});
私はmyMethod()
を呼び出して、私はまだ(two
とthree
に同じ)one.called
上の偽取得one - two - three
にスパイを持っているにもかかわらず
私はここで何をしないのですか?
ありがとうございます! fn
を変更しないsinon.spy(fn)
を呼び出す
[関数呼び出しの検証とサイロンスパイを使用した引数の検査]の可能な複製(https://stackoverflow.com/questions/29800733/verifying-function-call-and-inspecting-arguments-using-sinon-spies) –