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
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:
- Created 5 years ago
- Comments:15 (4 by maintainers)
Top 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 >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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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:
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.