jest: toBeCalledWith failure output is weird with multiple mismatched calls

πŸ› Bug Report

test("reproduce issue", () => {
    let fn = jest.fn();
    fn(1);
    fn(2);
    fn(3);

    expect(fn).toBeCalledWith((5));
});

yields image

Expected behavior

Maybe a list of what is called with? Something like the failure output for the toBeCalled() matcher

Run npx envinfo --preset jest

Paste the results here:

Environment:
  OS:  macOS High Sierra 10.13.6
  Node:  8.11.1
  Yarn:  1.12.1
  npm:  5.6.0
  Watchman:  4.9.4
  Xcode:  Xcode 9.4.1 Build version 9F2000
  Android Studio:  3.2 AI-181.5540.7.32.5056338

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15 (11 by maintainers)

Most upvoted comments

Ouch. Good timing. I looked at spyMatchers yesterday for the first time in about a year 😦

At lot of work there. It seems like toHaveBeenCalledTimes will be our warm up exercise.

Yes, I agree that .not.toHaveBeenCalled is an analogy, with called args vertical instead of horizontal.

What do y’all think of first draft of improved report, with more complicated example calls:

Expected args: [5]
Received args: [1]
               [2, 'deux']
               [3, 'trois', 'drei']