I have a one method that looks like this:
doSomething(){
return somethingPromisy().then((blerp) => {
// do something with blerp
return blerp; // Modified, of course
});
};
Then I have another method that looks like this:
doSomethingElse(){
stepOne();
var x = stepTwo();
var y = stepThree(x);
doSomething.then((data) => {
stepFour(data + y);
});
};
I'm using mocha+chai+sinon to test this code, in particular, doSomethingElse, and then I want to make some assertions - but how can I guarantee that the promise will be resolved by the time I make assertions? I know one option would be to change it to:
doSomethingElse(){
/* ... */
return doSomething.then(...);
};
If I do this, then it's pretty easy to write my test because then it's:
return doSomethingElse().then(() => {
someFake.lastCall.args.should.deep.equal(expectedData);
});
In my test and everything is fine. But should I be returning the promise simply for the sake of returning the promise? I don't actually care about any kind of return value from doSomethingElse - I only care that when I'm testing that the function in doSomething.then was called, i.e. the doSomething promise has been resolved by the time I do my assertions.
So what's the "best" way to go about this?
Aucun commentaire:
Enregistrer un commentaire