You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently there is no way to test whether a spy is only called once with certain arguments but both assertions are essential.
This currently requires two assertions: expect(spy).toHaveBeenCalledWith(...args) and expect(spy).toHaveBeenCalledOnce().
I argue this case is so common that there should be a matcher included by default for this.
Suggested solution
Add a new default assertion matcher "toHaveBeenCalledOnceWith" which combines the checks of toHaveBeenCalledOnce and toHaveBeenCalledWith:
checks the spy has been called once
the provided arguments match
The matcher should throw on error when there are less than two arguments.
Alternative
Use expect.extend per project
Add a more universal way to combine multiple assertion matchers
Additional context
There is an existing matcher for Jest via jest-extended.
I am willing to submit a PR for this if accepted.
Clear and concise description of the problem
Currently there is no way to test whether a spy is only called once with certain arguments but both assertions are essential.
This currently requires two assertions:
expect(spy).toHaveBeenCalledWith(...args)
andexpect(spy).toHaveBeenCalledOnce()
.I argue this case is so common that there should be a matcher included by default for this.
Suggested solution
Add a new default assertion matcher "toHaveBeenCalledOnceWith" which combines the checks of
toHaveBeenCalledOnce
andtoHaveBeenCalledWith
:The matcher should throw on error when there are less than two arguments.
Alternative
expect.extend
per projectAdditional context
There is an existing matcher for Jest via jest-extended.
I am willing to submit a PR for this if accepted.
Validations
The text was updated successfully, but these errors were encountered: