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

Support toHaveReceivedAnyCommand #201

Closed
yaronya opened this issue Jan 3, 2024 · 1 comment · Fixed by #202
Closed

Support toHaveReceivedAnyCommand #201

yaronya opened this issue Jan 3, 2024 · 1 comment · Fixed by #202
Labels
enhancement New feature or request

Comments

@yaronya
Copy link
Contributor

yaronya commented Jan 3, 2024

I'm migrating my Node.js AWS SDK v2 codebase to v3.
I'm using jest as my testing framework, and sometimes I have a long test matrix that accepts the relevant Command used as a parameter. The test matrix also supports a scenario where the Command is irrelevant, and therefore is undefined.

When I run .not.toHaveReceivedCommandWith(undefined) the code crashes, as it expects a valid Command.
I wish I was able to just .not.toHaveReceivedAnyCommand to settle this specific use-case. It's also a common matcher pattern in other popular custom matchers, like jest-extended

I'm not that familiar with the jest matchers framework, but willing to contribute if this makes sense :)

@yaronya yaronya added the enhancement New feature or request label Jan 3, 2024
@m-radzikowski
Copy link
Owner

Sure, if you want to contribute, please make a PR with this matcher.

In the meantime, you can achieve this with:

expect(clientMock.calls()).toBeGreaterThan(0);

Just remember to reset the mocks every test (clientMock.reset() or clientMock.resetHistory() in beforeEach / afterEach block).

I agree having a toHaveReceivedAnyCommand() matcher would be nice and more readable :)

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
Development

Successfully merging a pull request may close this issue.

2 participants