Skip to content

Conversation

@stschulte
Copy link
Owner

The new matcher can be used in similar way as
toHaveBeenCalledExactlyOnceWith of vitest but targeted against
AWS mocks

The common practice seems to be to not call tests "it should" but rather
specify the expected behaviour as facts, e.g. use "it passes" instead of
"it should pass"
Whenever compare call arguments (e.g. `toHaveReceivedCommandWith` we
internally use ObjectContaining and `asymmetricMatch` of `vitest`. This
is not only to allow partial matches, but also in order to use something
like `expect.any(String)` or `expect.stringMatching()`.

This now adds some tests to verify this does actually work as intended.
This includes a major version bump of @vitest/expect, so we should later
also bump the major version of our package.
When testing our custom matcher we want to ensure they also fail a test
appropiatly (e.g. you test a mock was never called, but it was indeed
called; we want to know this fails)

Previously we did write a test like a user would write the test but
instead of using `it` we use `if.fails`.

While this did work, we are unable to validate *why* the test fails. We
now don't assume failing tests but instead we wrap these in
`expect(...).toThrow`.

This should not only be easier to read but also allows us to capture the
error message to validate the test fails for the correct reason.
The new matcher can be used in similar way as
[toHaveBeenCalledExactlyOnceWith][1] of vitest but targeted against
AWS mocks

[1]: vitest-dev/vitest#6894
@stschulte stschulte merged commit 32a1b6d into main Jan 17, 2025
1 check passed
@stschulte stschulte deleted the new-matcher branch January 17, 2025 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant