gpt4 book ai didi

javascript - 如何在调用时从 spy.on(object, 'funcName') 返回虚假数据?

转载 作者:行者123 更新时间:2023-11-29 10:36:18 25 4
gpt4 key购买 nike

不知道有没有功能!请告诉我这可能吗?

类似的东西:

spy(obj, 'funcName').and.returnValue(5); // spy will return a fake data when 'funcName'called.

嗯,我正在使用 mochachai-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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com