不知道有没有功能! 请告诉我这可能吗?
类似的东西:
spy(obj, 'funcName').and.returnValue(5); // spy will return a fake data when 'funcName'called.
嗯,我正在使用 mocha
,chai-spies
最佳答案
而不是 spy ,看看为此使用 stub 。
根据文档:
Test stubs are functions (spies) with pre-programmed behavior. They support the full test spy API in addition to methods which can be used to alter the stub’s behavior.
stub 有一个“返回”方法来完成您正在寻找的事情。
var stub = sinon.stub();
stub.returns(54)
stub(); // 54
关于javascript - 如何在调用时从 spy.on(object, 'funcName') 返回虚假数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35812663/