【发布时间】:2022-06-17 23:48:08
【问题描述】:
我有一个多次调用间谍的测试:
// example.test.js
it("Fails but doesn't log all calls", () => {
const spy = jest.fn();
spy("1");
spy("2");
spy("3");
spy("4");
spy("5");
expect(spy).toHaveBeenCalledWith("not 1");
});
Jest 会截断输出,因此Received 下仅列出前 3 个调用:
// jest example.test.js
expect(jest.fn()).toHaveBeenCalledWith(...expected)
Expected: "not 1"
Received
1: "1"
2: "2"
3: "3"
Number of calls: 5
10 | spy("4");
11 | spy("5");
> 12 | expect(spy).toHaveBeenCalledWith("not 1");
| ^
13 | });
14 |
我如何获得完整的调用列表以在终端中显示断言失败?
Received
1: "1"
2: "2"
3: "3"
4: "4"
5: "5"
【问题讨论】:
-
spy.mock.calls?
标签: javascript jestjs