Skip to content

Commit 3830399

Browse files
authored
Update createAsyncThunk.mdx
1 parent 00502fa commit 3830399

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

docs/api/createAsyncThunk.mdx

+4-4
Original file line numberDiff line numberDiff line change
@@ -507,25 +507,25 @@ const fetchUserById = createAsyncThunk(
507507
)
508508
```
509509

510-
### Testing Cancellation Behavior
510+
### Checking if a Promise Rejection was from an Error or Cancellation
511511

512-
To test behavior around thunk cancellation, you can check various properties on the `meta` object of the dispatched action.
512+
To investigate behavior around thunk cancellation, you can inspect various properties on the `meta` object of the dispatched action.
513513
If a thunk was cancelled, the result of the promise will be a `rejected` action (regardless of whether that action was actually dispatched to the store).
514514

515515
- If it was cancelled before execution, `meta.condition` will be true.
516516
- If it was aborted while running, `meta.aborted` will be true.
517517
- If neither of those is true, the thunk was not cancelled, it was simply rejected, either by a Promise rejection or `rejectWithValue`.
518518
- If the thunk was not rejected, both `meta.aborted` and `meta.condition` will be `undefined`.
519519

520-
So to test that a thunk was cancelled before executing, you can do the following:
520+
So if you wanted to test that a thunk was cancelled before executing, you can do the following:
521521

522522
```ts no-transpile
523523
import { createAsyncThunk, isRejected } from '@reduxjs/toolkit'
524524

525525
test('this thunk should always be skipped', async () => {
526526
const thunk = createAsyncThunk(
527527
'users/fetchById',
528-
async () => 'This promise should never be entered',
528+
async () => throw new Error('This promise should never be entered'),
529529
{
530530
condition: () => false,
531531
}

0 commit comments

Comments
 (0)