Merge branch 'renovate/playwright' into 'main'
[ProtonMail-WebClient.git] / packages / redux-shared-store / test.ts
blobd3e57e8539ba1576f5ac3dffec7e9edd0278319c
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>({
5     preloadedState,
6     reducer,
7     extraThunkArguments,
8 }: {
9     reducer: Reducer<S, A, P> | ReducersMapObject<S, A, P>;
10     preloadedState?: P;
11     extraThunkArguments: T;
12 }) => {
13     const listenerMiddleware = createListenerMiddleware({ extra: extraThunkArguments });
14     const store = configureStore({
15         preloadedState,
16         reducer,
17         middleware: (getDefaultMiddleware) =>
18             getDefaultMiddleware({
19                 thunk: { extraArgument: extraThunkArguments },
20             }).prepend(listenerMiddleware.middleware),
21     });
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;
29     return {
30         store,
31         startListening,
32     };