gpt4 book ai didi

javascript - 在流程 : how to stub a method in mocha? 中编写规范

转载 作者:行者123 更新时间:2023-11-30 20:16:18 25 4
gpt4 key购买 nike

A类有一个只读属性bb有方法c,在A#methodF中,有一个声明:

const v = await this.b.c();

在 A#methodF 的规范中,我想 stub c:

a.b.c = sinon.stub().resolves({myDesiredResult})(其中 aA 的实例)

但是 flow check 给出:

Cannot assign sinon.stub().resolves(...) to a.b.c because property c is not writable.

问题:如何让c返回我想要的结果?

最佳答案

您的问题是您没有正确使用 sinon.stub。当您真的想将 stub 分配给新变量时,您正试图将 a.b.c 设置为新值( stub )。 sinon.stub 的语法是这样的 ( docs ):

var stub = sinon.stub(object, "method");

所以在你的情况下:

var cStub = sinon.stub(a.b, "c").resolves({myDesiredResult})

关于javascript - 在流程 : how to stub a method in mocha? 中编写规范,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51887486/

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