question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

toBeCalledWith failure output is weird with multiple mismatched calls

See original GitHub issue

🐛 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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
pedrottimarkcommented, Feb 14, 2019

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']
0reactions
github-actions[bot]commented, May 11, 2021

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest passing an object to expect().toBeCalledWith()
The problem is I want to test a function that takes object as a parameter so when you call expect(myFunc).toBeCalledWith(object); the test ...
Read more >
Expect · Jest
In this case, toBe is the matcher function. There are a lot of different matcher functions, documented below, to help you test different...
Read more >
API Reference | Vitest
A blazing fast unit test framework powered by Vite.
Read more >
Jest Expect - w3resource
Your code will still work if you mix them up, but the error messages that you get on failing tests will look strange....
Read more >
Best Practices for Spies, Stubs and Mocks in Sinon.js
If you look back at the example function, we call two functions in it ... we can check many different results by using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found