如何在 Sinon 中存根一系列方法? [英] How do I stub a chain of methods in Sinon?
本文介绍了如何在 Sinon 中存根一系列方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何使用存根替换一个函数.
I know how to use stub to replace one function.
sandbox.stub(Cars, "findOne",
() => {return car1 });
但是现在我的函数中有一行我想测试我需要存根看起来像这样
But now I have a line in my function I want to test that I need to stub that looks like this
Cars.find().fetch()
所以这里有一个函数链,我不确定我需要做什么.如何存根查找"以返回可用于存根获取"的内容?
So there is a chain of function here and I'm unsure what I need to do. How do I stub "find" to return something that I can use to stub "fetch"?
推荐答案
试试这个:
sandbox.stub(Cars, "find", () => {
return {
fetch: sinon.stub().returns(anything);
};
});
这篇关于如何在 Sinon 中存根一系列方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文