Predict toHaveBeenCalledWith
预测输出 中等
题目
将这个测试通过 or 失败?
代码
const mockFn = jest.fn();
mockFn('hello', 'world');
test('called with args', () => {
expect(mockFn).toHaveBeenCalledWith('hello', 'world');
});
提示
mock 是 called 使用 'hello' and '世界'.
解释
测试通过. toHaveBeenCalledWith('hello', '世界') 检查那个 mock 是 called 使用精确地那些实参 at 最少一次. 由于 mockFn('hello', '世界') 是 called 使用那些精确实参, assertion succeeds.
相关资源
相关课程
- Mocking
Using mocks 到 isolate code.
查阅不认识的术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。
动手做项目
通过引导式项目应用所学,含起始代码与解决方案。