【问题标题】:Output all received mock calls in Jest在 Jest 中输出所有收到的模拟呼叫
【发布时间】: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


猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-04-07
  • 2020-04-18
  • 2014-05-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多