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
Copy file name to clipboardExpand all lines: docs/ExpectAPI.md
+25-5Lines changed: 25 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -67,7 +67,9 @@ test('numeric ranges', () => {
67
67
});
68
68
```
69
69
70
-
_Note_: In TypeScript, when using `@types/jest` for example, you can declare the new `toBeWithinRange` matcher in the imported module like this:
70
+
:::note
71
+
72
+
In TypeScript, when using `@types/jest` for example, you can declare the new `toBeWithinRange` matcher in the imported module like this:
71
73
72
74
```ts
73
75
interfaceCustomMatchers<R=unknown> {
@@ -83,6 +85,8 @@ declare global {
83
85
}
84
86
```
85
87
88
+
:::
89
+
86
90
#### Async Matchers
87
91
88
92
`expect.extend` also supports async matchers. Async matchers return a Promise so you will need to await the returned value. Let's use an example matcher to illustrate the usage of them. We are going to implement a matcher called `toBeDivisibleByExternalValue`, where the divisible number is going to be pulled from an external source.
Note: the nth argument must be positive integer starting from 1.
910
+
:::note
911
+
912
+
The nth argument must be positive integer starting from 1.
913
+
914
+
:::
903
915
904
916
### `.toHaveLength(number)`
905
917
@@ -1205,7 +1217,11 @@ describe('the La Croix cans on my desk', () => {
1205
1217
});
1206
1218
```
1207
1219
1208
-
> Note: `.toEqual` won't perform a _deep equality_ check for two errors. Only the `message` property of an Error is considered for equality. It is recommended to use the `.toThrow` matcher for testing against errors.
1220
+
:::tip
1221
+
1222
+
`.toEqual` won't perform a _deep equality_ check for two errors. Only the `message` property of an Error is considered for equality. It is recommended to use the `.toThrow` matcher for testing against errors.
1223
+
1224
+
:::
1209
1225
1210
1226
If differences between properties do not help you to understand why a test fails, especially if the report is large, then you might move the comparison into the `expect` function. For example, use `equals` method of `Buffer` class to assert whether or not buffers contain the same content:
1211
1227
@@ -1340,7 +1356,11 @@ test('throws on octopus', () => {
1340
1356
});
1341
1357
```
1342
1358
1343
-
> Note: You must wrap the code in a function, otherwise the error will not be caught and the assertion will fail.
1359
+
:::tip
1360
+
1361
+
You must wrap the code in a function, otherwise the error will not be caught and the assertion will fail.
1362
+
1363
+
:::
1344
1364
1345
1365
You can provide an optional argument to test that a specific error is thrown:
0 commit comments