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
> The `AsymmetricMatchersContaining` controls the matcher types available as asymmetric matchers on the `expect` object (e.g. `expect.objectContaining()`).
5
+
To expose my `.toMatchSchema()` matcher as an asymmetric matcher, I need to... do nothing! Vitest automatically provides both symmetric and asymmetric versions for your custom matchers, including type definitions.
16
6
17
-
With this change, the type error in the `src/fetch-user.test.ts` is finally gone! 🎉
7
+
All that's left for me to do is to use the asymmetric version of the `toMatchSchema()` matcher in tests:
18
8
19
9
```ts filename=src/fetch-user.test.ts highlight=6
20
10
import { fetchUser } from'./fetch-user'
@@ -26,9 +16,7 @@ test('returns the user by id', async () => {
26
16
})
27
17
```
28
18
29
-
This means that I can use the `.toMatchSchema()` matcher as asymmetric, which is exactly what I need to complete the test case for user transactions.
30
-
31
-
In `src/fetch-transaction.test.ts`, I will write the remaining test:
19
+
And in `src/fetch-transaction.test.ts`, I will write the remaining test:
@@ -45,7 +33,7 @@ test('fetches a transaction between two users', async () => {
45
33
})
46
34
```
47
35
48
-
> 🦉 Notice how I'm using schema validation to make sure that transaction's `issuer` and `recipient` properties both match the `userSchema`.
36
+
> 🦉 Notice the usage of the `Transaction` type as the type argument to the default `.toEqual` matcher. It ensures that the expected value I pass to that matcher is type-safe.
0 commit comments