@@ -18,13 +18,18 @@ import {
18
18
expectExactType ,
19
19
expectType ,
20
20
setupApiStore ,
21
+ withProvider ,
21
22
useRenderCounter ,
22
23
waitMs ,
23
24
} from './helpers'
24
25
import { server } from './mocks/server'
25
26
import type { AnyAction } from 'redux'
26
27
import type { SubscriptionOptions } from '@reduxjs/toolkit/dist/query/core/apiState'
27
- import { createListenerMiddleware , SerializedError } from '@reduxjs/toolkit'
28
+ import {
29
+ createListenerMiddleware ,
30
+ SerializedError ,
31
+ configureStore ,
32
+ } from '@reduxjs/toolkit'
28
33
import { renderHook } from '@testing-library/react'
29
34
import { delay } from '../../utils'
30
35
@@ -651,6 +656,39 @@ describe('hooks tests', () => {
651
656
const res = await resPromise
652
657
expect ( res . data ! . amount ) . toBeGreaterThan ( originalAmount )
653
658
} )
659
+
660
+ describe ( 'Hook middleware requirements' , ( ) => {
661
+ let mock : jest . SpyInstance
662
+
663
+ beforeEach ( ( ) => {
664
+ mock = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
665
+ } )
666
+
667
+ afterEach ( ( ) => {
668
+ mock . mockReset ( )
669
+ } )
670
+
671
+ test ( 'Throws error if middleware is not added to the store' , async ( ) => {
672
+ const store = configureStore ( {
673
+ reducer : {
674
+ [ api . reducerPath ] : api . reducer ,
675
+ } ,
676
+ } )
677
+
678
+ const doRender = ( ) => {
679
+ const { result } = renderHook (
680
+ ( ) => api . endpoints . getIncrementedAmount . useQuery ( ) ,
681
+ {
682
+ wrapper : withProvider ( store ) ,
683
+ }
684
+ )
685
+ }
686
+
687
+ expect ( doRender ) . toThrowError (
688
+ / W a r n i n g : M i d d l e w a r e f o r R T K - Q u e r y A P I a t r e d u c e r P a t h " a p i " h a s n o t b e e n a d d e d t o t h e s t o r e /
689
+ )
690
+ } )
691
+ } )
654
692
} )
655
693
656
694
describe ( 'useLazyQuery' , ( ) => {
0 commit comments