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
Since Vitest 3.2, you can extend the `Matchers` interface to have type-safe assertions in `expect.extend`, `expect().*`, and `expect.*` methods at the same time. Previously, you had to define separate interfaces for each of them.
56
+
:::
40
57
41
58
::: warning
42
59
Don't forget to include the ambient declaration file in your `tsconfig.json`.
@@ -56,35 +73,45 @@ interface ExpectationResult {
56
73
```
57
74
58
75
::: warning
59
-
If you create an asynchronous matcher, don't forget to `await` the result (`await expect('foo').toBeFoo()`) in the test itself.
76
+
If you create an asynchronous matcher, don't forget to `await` the result (`await expect('foo').toBeFoo()`) in the test itself::
77
+
78
+
```ts
79
+
expect.extend({
80
+
async toBeAsyncAssertion() {
81
+
// ...
82
+
}
83
+
})
84
+
85
+
awaitexpect().toBeAsyncAssertion()
86
+
```
60
87
:::
61
88
62
89
The first argument inside a matcher's function is the received value (the one inside `expect(received)`). The rest are arguments passed directly to the matcher.
63
90
64
-
Matcher function have access to `this` context with the following properties:
91
+
Matcher function has access to `this` context with the following properties:
65
92
66
-
-`isNot`
93
+
###`isNot`
67
94
68
-
Returns true, if matcher was called on `not` (`expect(received).not.toBeFoo()`).
95
+
Returns true, if matcher was called on `not` (`expect(received).not.toBeFoo()`).
69
96
70
-
-`promise`
97
+
###`promise`
71
98
72
-
If matcher was called on `resolved/rejected`, this value will contain the name of modifier. Otherwise, it will be an empty string.
99
+
If matcher was called on `resolved/rejected`, this value will contain the name of modifier. Otherwise, it will be an empty string.
73
100
74
-
-`equals`
101
+
###`equals`
75
102
76
-
This is a utility function that allows you to compare two values. It will return `true` if values are equal, `false` otherwise. This function is used internally for almost every matcher. It supports objects with asymmetric matchers by default.
103
+
This is a utility function that allows you to compare two values. It will return `true` if values are equal, `false` otherwise. This function is used internally for almost every matcher. It supports objects with asymmetric matchers by default.
77
104
78
-
-`utils`
105
+
###`utils`
79
106
80
-
This contains a set of utility functions that you can use to display messages.
107
+
This contains a set of utility functions that you can use to display messages.
81
108
82
109
`this` context also contains information about the current test. You can also get it by calling `expect.getState()`. The most useful properties are:
83
110
84
-
-`currentTestName`
111
+
###`currentTestName`
85
112
86
-
Full name of the current test (including describe block).
113
+
Full name of the current test (including describe block).
0 commit comments