jestjs - ".toBeCalled"和 ".toHaveBeenCalled"有什么区别?

标签 jestjs

什么时候应该调用这些方法中的每一个,为什么?

const spyStart = spyOn(el, 'func1');
expect(spyStart).toHaveBeenCalled();


const spyStart = spyOn(el, 'func1');
expect(spyStart).toBeCalled();

最佳答案

其实.toBeCalled.toHaveBeenCalled 的别名,所以他们做同样的事情

关于jestjs - ".toBeCalled"和 ".toHaveBeenCalled"有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63130179/

相关文章:

node.js - Jest 单元测试不会等待 axios 响应

reactjs - 当我使用 react 测试库、react.lazy 和 suspense Jest 运行相同的测试两次时,为什么加载程序没有在第二次测试中显示?

typescript - 如何在 Jest 单元测试中模拟 `created` Vue 生命周期钩子(Hook)中调用的方法,而不使用 `methods` 中已弃用的 `shallowMount` 参数?

unit-testing - 如何在 React Jest 测试中获取 "mock"navigator.geolocation

reactjs - 使用 Jest 和 react 测试库进行单元测试自定义 Hook

reactjs - 在哪里可以找到 Jest __snapshots__ 目录

reactjs - 使用 preloadedState : redux store gets out of sync when having a manual import of store in a function 在 React 中进行测试

typescript - Jest Mock + Typescript 错误 TS2339

javascript - 使用 jest 测试提交以获取的 FormData

angular - '引用错误: define is not defined' when testing Angular app with jest using ApplicationInsights-js