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: CHANGELOG.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,7 +44,10 @@
44
44
-`[*]` Depend on exact versions of monorepo dependencies instead of `^` range ([#14553](https://github.com/facebook/jest/pull/14553))
45
45
-`[*]`[**BREAKING**] Add ESM wrapper for all of Jest's modules ([#14661](https://github.com/jestjs/jest/pull/14661))
46
46
-`[babel-jest, babel-preset-jest]`[**BREAKING**] Increase peer dependency of `@babel/core` to `^7.11` ([#14109](https://github.com/jestjs/jest/pull/14109))
Copy file name to clipboardExpand all lines: docs/ExpectAPI.md
-22Lines changed: 0 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -144,8 +144,6 @@ Although the `.toBe` matcher **checks** referential identity, it **reports** a d
144
144
145
145
### `.toHaveBeenCalled()`
146
146
147
-
Also under the alias: `.toBeCalled()`
148
-
149
147
Use `.toHaveBeenCalledWith` to ensure that a mock function was called with specific arguments. The arguments are checked with the same algorithm that `.toEqual` uses.
150
148
151
149
For example, let's say you have a `drinkAll(drink, flavour)` function that takes a `drink` function and applies it to all available beverages. You might want to check that `drink` gets called for `'lemon'`, but not for `'octopus'`, because `'octopus'` flavour is really weird and why would anything be octopus-flavoured? You can do that with this test suite:
@@ -174,8 +172,6 @@ describe('drinkAll', () => {
174
172
175
173
### `.toHaveBeenCalledTimes(number)`
176
174
177
-
Also under the alias: `.toBeCalledTimes(number)`
178
-
179
175
Use `.toHaveBeenCalledTimes` to ensure that a mock function got called exact number of times.
180
176
181
177
For example, let's say you have a `drinkEach(drink, Array<flavor>)` function that takes a `drink` function and applies it to array of passed beverages. You might want to check that drink function was called exact number of times. You can do that with this test suite:
Use `.toHaveBeenCalledWith` to ensure that a mock function was called with specific arguments. The arguments are checked with the same algorithm that `.toEqual` uses.
196
190
197
191
For example, let's say that you can register a beverage with a `register` function, and `applyToAll(f)` should apply the function `f` to all registered beverages. To make sure this works, you could write:
@@ -208,8 +202,6 @@ test('registration applies correctly to orange La Croix', () => {
208
202
209
203
### `.toHaveBeenLastCalledWith(arg1, arg2, ...)`
210
204
211
-
Also under the alias: `.lastCalledWith(arg1, arg2, ...)`
212
-
213
205
If you have a mock function, you can use `.toHaveBeenLastCalledWith` to test what arguments it was last called with. For example, let's say you have a `applyToAllFlavors(f)` function that applies `f` to a bunch of flavors, and you want to ensure that when you call it, the last flavor it operates on is `'mango'`. You can write:
214
206
215
207
```js
@@ -222,8 +214,6 @@ test('applying to all flavors does mango last', () => {
Also under the alias: `.nthCalledWith(nthCall, arg1, arg2, ...)`
226
-
227
217
If you have a mock function, you can use `.toHaveBeenNthCalledWith` to test what arguments it was nth called with. For example, let's say you have a `drinkEach(drink, Array<flavor>)` function that applies `f` to a bunch of flavors, and you want to ensure that when you call it, the first flavor it operates on is `'lemon'` and the second one is `'octopus'`. You can write:
228
218
229
219
```js
@@ -243,8 +233,6 @@ The nth argument must be positive integer starting from 1.
243
233
244
234
### `.toHaveReturned()`
245
235
246
-
Also under the alias: `.toReturn()`
247
-
248
236
If you have a mock function, you can use `.toHaveReturned` to test that the mock function successfully returned (i.e., did not throw an error) at least one time. For example, let's say you have a mock `drink` that returns `true`. You can write:
Use `.toHaveReturnedTimes` to ensure that a mock function returned successfully (i.e., did not throw an error) an exact number of times. Any calls to the mock function that throw an error are not counted toward the number of times the function returned.
265
251
266
252
For example, let's say you have a mock `drink` that returns `true`. You can write:
Use `.toHaveLastReturnedWith` to test the specific value that a mock function last returned. If the last call to the mock function threw an error, then this matcher will fail no matter what value you provided as the expected return value.
303
285
304
286
For example, let's say you have a mock `drink` that returns the name of the beverage that was consumed. You can write:
Also under the alias: `.nthReturnedWith(nthCall, value)`
322
-
323
303
Use `.toHaveNthReturnedWith` to test the specific value that a mock function returned for the nth call. If the nth call to the mock function threw an error, then this matcher will fail no matter what value you provided as the expected return value.
324
304
325
305
For example, let's say you have a mock `drink` that returns the name of the beverage that was consumed. You can write:
@@ -782,8 +762,6 @@ describe('the La Croix cans on my desk', () => {
782
762
783
763
### `.toThrow(error?)`
784
764
785
-
Also under the alias: `.toThrowError(error?)`
786
-
787
765
Use `.toThrow` to test that a function throws when it is called. For example, if we want to test that `drinkFlavor('octopus')` throws, because octopus flavor is too disgusting to drink, we could write:
0 commit comments