Kur*_*urt 3 javascript sinon typescript
创建一个在重复调用时返回不同值的存根似乎很简单: 是否可以在单个测试中对方法进行两次存根以返回不同的结果?
但是,我如何使用解析多个调用的异步方法来做到这一点?
sinon(module, "myFunction")
.resolves('a')
.resolves('b')
Run Code Online (Sandbox Code Playgroud)
需要明确的是,在上面的片段中,第二个解析会覆盖第一个,因此它总是返回“b”。我想要“myFunction”首先解析“a”然后解析“b”的行为。
这是解决方案:
sinon(module, "myFunction")
.onFirstCall().resolves('a')
.onSecondCall().resolves('b')
Run Code Online (Sandbox Code Playgroud)