samedi 20 août 2016

Sinon stubbing a function passed as a parameter

I have the following Example class:

function Example() {...}
Example.prototype.someFunc1() {...}
Example.prototype.someFunc2() {...}
Example.prototype.func(func) {var res = func(); ...}

I usually call Example#func() as follows:

var example = new Example();
example.func(example.someFunc1)
/ Or like this, depending on what I want
example.func(example.someFunc2)

Now I stub Example#someFunc1/2() as follows in my test:

var example = new Example();
sinon.stub(example, 'someFunc1').returns(...);
exmaple.func(example.someFunc1);

Problem is that Example#someFunc1() is not being stubbed this way and being called normally. What can I do in such situation ?

Aucun commentaire:

Enregistrer un commentaire