toHaveBeenCalledOnceWith only asserts a match on the first parameter.
See original GitHub issueI’m not sure if this would be classed as a bug or a feature, so apologies for any mistakes raising the issue.
Feature Request
Description: toHaveBeenCalledOnceWith currently only matches against the first parameter provided to a mock function.
Possible solution:
In toHaveBeenCalledOnceWith.js
, line 40 reads
const pass = passOnce && this.equals(expected, received.mock.calls[0][0]);
I believe that this should probably be changed to this.equals(expected, received.mock.calls[0]);
and assert equality on the whole array of parameters passed to the mock function in the first call. This may need the function declaration to be changed to toHaveBeenCalledOnceWith(received, ...expected)
or similar to handle multiple arguments.
If this is desired, or not so simple to implement, it would be good to make this clear in the documentation.
Issue Analytics
- State:
- Created a year ago
- Comments:6
Top GitHub Comments
Oh, I’m still thinking this issue is describing a separate problem from #518, is it not? Jest’s
toHaveBeenCalledOnceWith
matches on all arguments, not just the first one.I haven’t found a way to make this work with varargs. Jest seems to pass only the first parameter as
expected
into the matcher. I’m looking in Jest code to see if there’s a way this behavior can be changed, but I’m suspecting not.