として渡された関数をスタブ:Sinon私は、次の例のクラスを持っているパラメータ
function Example() {...}
Example.prototype.someFunc1() {...}
Example.prototype.someFunc2() {...}
Example.prototype.func(func) {var res = func(); ...}
私は通常、次のようにExample#func()
を呼び出して次のように
var example = new Example();
example.func(example.someFunc1)
// or like this, depending on what I want
example.func(example.someFunc2)
を今、私は私のテストでExample#someFunc1()
スタブ:
var example = new Example();
sinon.stub(example, 'someFunc1').returns(...);
exmaple.func(example.someFunc1);
問題は、Example#someFunc1()
はbeinではありませんgはこのようにスタブされ、普通に呼ばれます。このような状況で私は何ができますか?
これは再現できません。 https://gist.github.com/davelnewton/a2b786fd485b6767606bcb20942c4616 –
@DaveNewton私は作った:https://jsfiddle.net/f7p7z5fL/ – Jorayen