1 import { TypedStartListening, configureStore, createListenerMiddleware } from '@reduxjs/toolkit';
2 import type { Action, Reducer, ReducersMapObject } from 'redux';
4 export const getTestStore = <T, A extends Action, S = any, P = S>({
9 reducer: Reducer<S, A, P> | ReducersMapObject<S, A, P>;
11 extraThunkArguments: T;
13 const listenerMiddleware = createListenerMiddleware({ extra: extraThunkArguments });
14 const store = configureStore({
17 middleware: (getDefaultMiddleware) =>
18 getDefaultMiddleware({
19 thunk: { extraArgument: extraThunkArguments },
20 }).prepend(listenerMiddleware.middleware),
23 type State = ReturnType<typeof store.getState>;
24 type Dispatch = typeof store.dispatch;
25 type ExtraArgument = typeof extraThunkArguments;
27 type AppStartListening = TypedStartListening<State, Dispatch, ExtraArgument>;
28 const startListening = listenerMiddleware.startListening as AppStartListening;