Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toHaveReceivedCommand should throw an error if it receives a second parameter. #191

Closed
shopsinc opened this issue Nov 7, 2023 · 2 comments · Fixed by #199
Closed

toHaveReceivedCommand should throw an error if it receives a second parameter. #191

shopsinc opened this issue Nov 7, 2023 · 2 comments · Fixed by #199
Labels
enhancement New feature or request

Comments

@shopsinc
Copy link

shopsinc commented Nov 7, 2023

It is very easy to write tests that will always pass if you incorrectly use toHaveReceivedCommand instead of toHaveReceivedCommandWith. It would be nice if toHaveReceivedCommand threw an error or warned you when you pass in a second parameter so you don't make that mistake.

This code will pass no matter what the second parameter is. It would be nice if it would save me from my own stupidity.

expect(schedulerMockClient).toHaveReceivedCommand(DeleteScheduleCommand, {
      Name: 'I AM BAD'
 })

It needs to be like this if you want it to actually fail.

expect(schedulerMockClient).toHaveReceivedCommandWith(DeleteScheduleCommand, {
      Name: 'I AM BAD'
 })
@shopsinc shopsinc added the enhancement New feature or request label Nov 7, 2023
m-radzikowski added a commit that referenced this issue Dec 31, 2023
Prevents accidental calling toHaveReceivedCommand(Cmd, {})
instead of toHaveReceivedCommandWith(Cmd, {})

Closes #191
m-radzikowski added a commit that referenced this issue Jan 1, 2024
…199)

* feat(jest): fail if more than expected matcher arguments are passed

Prevents accidental calling toHaveReceivedCommand(Cmd, {})
instead of toHaveReceivedCommandWith(Cmd, {})

Closes #191
@m-radzikowski
Copy link
Owner

Good point. I've added a check in v3.1.0-beta.0. You can test it if you have a moment.

@shopsinc
Copy link
Author

shopsinc commented Apr 2, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants