angular - 需要调用toHaveBeenCalledTimes

标签 angular jasmine karma-runner

我有一个断言

toHaveBeenCalledWith

您认为还有必要断言

toHaveBeenCalledTimes(1)

谢谢

最佳答案

toHaveBeenCalledWith(arg1) 验证是否存在至少一个使用传入参数的调用。

调用 > 0 && arg === arg1

toHaveBeenCalledTimes(1) 验证是否被调用一次与任何论点。

调用 === 1

因此 toHaveBeenCalledTimes() 不是必需的,除非您想确保它只被调用了非常特定的次数。

关于angular - 需要调用toHaveBeenCalledTimes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58637366/

相关文章:

javascript - 数据初始化 promise

angular - 在 Angular2 中使用标记

testing - 在调用组件中的异步服务之前测试值是否设置正确

html - div 内的图像根据 Edge 上的标题长度调整大小

html - Angular自定义标签不渲染和执行功能

javascript - 如何对 Polyfilled WebComponents 自定义元素进行单元测试

javascript - AngularJS单元测试: using async/await with Jasmine

javascript - Angular Testing - promise 不返回数据

angular - 类型错误 : Cannot read property 'subscribe' of undefined in unit test

javascript - $injector 在我的测试中不起作用,为什么?