Fill: jest.spyOn
填空题 中等
题目
Fill in 空白到 spy on console.log:
代码
const spy = ___(console, 'log');
console.log('hello');
expect(spy).toHaveBeenCalled();
提示
Jest 有 spyOn 函数.
解释
正确答案是 jest.spyOn. jest.spyOn(对象, methodName) wraps existing 方法使用 spy 那个记录 calls 虽然 still calling 原始 implementation. 你能 later assert on 如何方法是 called.
相关资源
相关课程
- Stubs and Spies
理解测试 doubles.
查阅不认识的术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。
动手做项目
通过引导式项目应用所学,含起始代码与解决方案。