Skip to content

Commit 856b525

Browse files
committed
Add some type tests for startListening.withTypes
1 parent ad99ac0 commit 856b525

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

packages/toolkit/src/listenerMiddleware/tests/listenerMiddleware.test-d.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import type { TypedStartListening } from '@reduxjs/toolkit'
2+
import {
3+
configureStore,
4+
createAsyncThunk,
5+
createListenerMiddleware,
6+
createSlice,
7+
} from '@reduxjs/toolkit'
18
import type { Action } from 'redux'
29
import type { ThunkAction } from 'redux-thunk'
310
import { expectTypeOf } from 'vitest'
4-
import { createListenerMiddleware } from '..'
5-
import { configureStore } from '../../configureStore'
6-
import { createAsyncThunk } from '../../createAsyncThunk'
7-
import { createSlice } from '../../createSlice'
811

912
export interface CounterState {
1013
counter: number
@@ -69,27 +72,30 @@ describe('listenerMiddleware.withTypes<RootState, AppDispatch>()', () => {
6972
CounterState,
7073
AppDispatch
7174
>()
75+
76+
expectTypeOf(startAppListening).toEqualTypeOf<
77+
TypedStartListening<CounterState, AppDispatch>
78+
>()
79+
7280
startAppListening({
7381
predicate: increment.match,
7482
effect: async (_, listenerApi) => {
7583
const stateBefore = listenerApi.getState()
7684

85+
expectTypeOf(stateBefore).toEqualTypeOf<CounterState>()
86+
7787
let takeResult = await listenerApi.take(increment.match, timeout)
7888
const stateCurrent = listenerApi.getState()
79-
expect(takeResult).toEqual([increment(), stateCurrent, stateBefore])
89+
90+
expectTypeOf(stateCurrent).toEqualTypeOf<CounterState>()
8091

8192
timeout = 1
8293
takeResult = await listenerApi.take(increment.match, timeout)
83-
expect(takeResult).toBeNull()
84-
85-
expectTypeOf<
86-
typeof takeResult
87-
>(takeResult).toEqualTypeOf<ExpectedTakeResultType>()
8894

8995
done = true
9096
},
9197
})
9298
})
9399

94-
test('addListener.withTypes', () => {})
100+
test.todo('addListener.withTypes', () => {})
95101
})

0 commit comments

Comments
 (0)