jest mocking
This commit is contained in:
@@ -1,20 +1,24 @@
|
||||
import { configureStore } from '@reduxjs/toolkit';
|
||||
import { combineReducers, configureStore } from '@reduxjs/toolkit';
|
||||
import { api } from './api';
|
||||
import { setupListeners } from '@reduxjs/toolkit/query';
|
||||
|
||||
export const store = configureStore({
|
||||
reducer: {
|
||||
// Add the generated reducer as a specific top-level slice
|
||||
[api.reducerPath]: api.reducer
|
||||
},
|
||||
// Adding the api middleware enables caching, invalidation, polling,
|
||||
// and other useful features of `rtk-query`.
|
||||
middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(api.middleware)
|
||||
const rootReducer = combineReducers({
|
||||
[api.reducerPath]: api.reducer
|
||||
});
|
||||
|
||||
setupListeners(store.dispatch);
|
||||
export function setupStore(preloadedState?: Partial<RootState>) {
|
||||
const store = configureStore({
|
||||
reducer: rootReducer,
|
||||
preloadedState: preloadedState,
|
||||
// Adding the api middleware enables caching, invalidation, polling,
|
||||
// and other useful features of `rtk-query`.
|
||||
middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(api.middleware)
|
||||
});
|
||||
setupListeners(store.dispatch);
|
||||
return store;
|
||||
}
|
||||
|
||||
// Infer the `RootState` and `AppDispatch` types from the store itself
|
||||
export type RootState = ReturnType<typeof store.getState>;
|
||||
// Inferred type: {posts: PostsState, comments: CommentsState, users: UsersState}
|
||||
export type AppDispatch = typeof store.dispatch;
|
||||
export type RootState = ReturnType<typeof rootReducer>;
|
||||
export type AppStore = ReturnType<typeof setupStore>;
|
||||
export type AppDispatch = AppStore['dispatch'];
|
||||
|
||||
Reference in New Issue
Block a user