|
| 1 | +import type { TypedStartListening } from '@reduxjs/toolkit' |
| 2 | +import { |
| 3 | + configureStore, |
| 4 | + createAsyncThunk, |
| 5 | + createListenerMiddleware, |
| 6 | + createSlice, |
| 7 | +} from '@reduxjs/toolkit' |
1 | 8 | import type { Action } from 'redux'
|
2 | 9 | import type { ThunkAction } from 'redux-thunk'
|
3 | 10 | import { expectTypeOf } from 'vitest'
|
4 |
| -import { createListenerMiddleware } from '..' |
5 |
| -import { configureStore } from '../../configureStore' |
6 |
| -import { createAsyncThunk } from '../../createAsyncThunk' |
7 |
| -import { createSlice } from '../../createSlice' |
8 | 11 |
|
9 | 12 | export interface CounterState {
|
10 | 13 | counter: number
|
@@ -69,27 +72,30 @@ describe('listenerMiddleware.withTypes<RootState, AppDispatch>()', () => {
|
69 | 72 | CounterState,
|
70 | 73 | AppDispatch
|
71 | 74 | >()
|
| 75 | + |
| 76 | + expectTypeOf(startAppListening).toEqualTypeOf< |
| 77 | + TypedStartListening<CounterState, AppDispatch> |
| 78 | + >() |
| 79 | + |
72 | 80 | startAppListening({
|
73 | 81 | predicate: increment.match,
|
74 | 82 | effect: async (_, listenerApi) => {
|
75 | 83 | const stateBefore = listenerApi.getState()
|
76 | 84 |
|
| 85 | + expectTypeOf(stateBefore).toEqualTypeOf<CounterState>() |
| 86 | + |
77 | 87 | let takeResult = await listenerApi.take(increment.match, timeout)
|
78 | 88 | const stateCurrent = listenerApi.getState()
|
79 |
| - expect(takeResult).toEqual([increment(), stateCurrent, stateBefore]) |
| 89 | + |
| 90 | + expectTypeOf(stateCurrent).toEqualTypeOf<CounterState>() |
80 | 91 |
|
81 | 92 | timeout = 1
|
82 | 93 | takeResult = await listenerApi.take(increment.match, timeout)
|
83 |
| - expect(takeResult).toBeNull() |
84 |
| - |
85 |
| - expectTypeOf< |
86 |
| - typeof takeResult |
87 |
| - >(takeResult).toEqualTypeOf<ExpectedTakeResultType>() |
88 | 94 |
|
89 | 95 | done = true
|
90 | 96 | },
|
91 | 97 | })
|
92 | 98 | })
|
93 | 99 |
|
94 |
| - test('addListener.withTypes', () => {}) |
| 100 | + test.todo('addListener.withTypes', () => {}) |
95 | 101 | })
|
0 commit comments