redux-toolkit: Middleware for RTK-Query API at reducerPath Error - "only" while running RTL tests

When defining the store for tests in React Testing Library - while working with RTK-query:

const rootReducer = combineReducers({
   users: userReducer,
   vpApi: vpApi.reducer 
})

const store = configureStore({
  reducer: rootReducer,
  middleware: [
    ...getDefaultMiddleware(),
    sagaMiddleware,
    vpApi.middleware,
  ],
});

This is giving an error while running RTL tests :

Warning: Middleware for RTK-Query API at reducerPath “vpApi” has not been added to the store. Features like automatic cache collection, automatic refetching etc. will not be available.

the same code is being used in the mock store for tests and the real store for the application - the application is working fine - but the tests are giving an error.

I have tried all combination of providing middleware to configureStore and the the same key is present in the rootReducer also.

Please help

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 26 (5 by maintainers)

Most upvoted comments

@phryneas @markerikson Thank you so much for your guidance.

const createApi = buildCreateApi(
  coreModule(),
  reactHooksModule({
    useDispatch: useSomeOtherDispatch,
    useSelector: useSomeOtherSelector,
    useStore: useSomeOtherstore
  })
)

ha, that’s great. I wasn’t aware that we can take this approach. I’ll try this, and let you know…if this can work. I genuinely understand and support that we should, never take the dual store approach. In our case, we have a mono-repo, with multiple apps. The old version of a web app, is talking to a different configured store and the new version is talking to the rtk store.

So, in process of migration, we have to take this hard route of having dual stores, for migrating in batches.