I want to use Sinon to stub a function that uses callbacks which resolve a promise:
const callback = (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
});
stub.me({}, callback);
I tried:
var stub = {
me: sinon.stub().yieldsTo("resolve", "my_data"),
};
but I keep getting mocha timeouts.
The code doesn't define a const
for callback. It's all in the stub.me function call. I just wrote it like that so it would be clear to read.
It's also wrapped in a new Promise((resolve,reject) => {} );
block.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…