1
- import { vi } from 'vitest '
1
+ import * as DevTools from '@internal/devtoolsExtension '
2
2
import type { StoreEnhancer } from '@reduxjs/toolkit'
3
3
import { Tuple } from '@reduxjs/toolkit'
4
4
import type * as Redux from 'redux'
5
- import type * as DevTools from '@internal/devtoolsExtension '
5
+ import { vi } from 'vitest '
6
6
7
7
vi . doMock ( 'redux' , async ( ) => {
8
8
const redux : any = await vi . importActual ( 'redux' )
@@ -15,45 +15,10 @@ vi.doMock('redux', async () => {
15
15
return redux
16
16
} )
17
17
18
- vi . doMock ( '@internal/devtoolsExtension' , async ( ) => {
19
- const devtools : typeof DevTools = await vi . importActual (
20
- '@internal/devtoolsExtension'
21
- )
22
- vi . spyOn ( devtools , 'composeWithDevTools' ) // @remap -prod-remove-line
23
- return devtools
24
- } )
25
-
26
- function originalReduxCompose ( ...funcs : Function [ ] ) {
27
- if ( funcs . length === 0 ) {
28
- // infer the argument type so it is usable in inference down the line
29
- return < T > ( arg : T ) => arg
30
- }
31
-
32
- if ( funcs . length === 1 ) {
33
- return funcs [ 0 ]
34
- }
35
-
36
- return funcs . reduce (
37
- ( a , b ) =>
38
- ( ...args : any ) =>
39
- a ( b ( ...args ) )
40
- )
41
- }
42
-
43
- function originalComposeWithDevtools ( ) {
44
- if ( arguments . length === 0 ) return undefined
45
- if ( typeof arguments [ 0 ] === 'object' ) return originalReduxCompose
46
- return originalReduxCompose . apply ( null , arguments as any as Function [ ] )
47
- }
48
-
49
18
describe ( 'configureStore' , async ( ) => {
50
- // RTK's internal `composeWithDevtools` function isn't publicly exported,
51
- // so we can't mock it. However, it _does_ try to access the global extension method
52
- // attached to `window`. So, if we mock _that_, we'll know if the enhancer ran.
53
- const mockDevtoolsCompose = vi
54
- . fn ( )
55
- . mockImplementation ( originalComposeWithDevtools )
56
- ; ( window as any ) . __REDUX_DEVTOOLS_EXTENSION_COMPOSE__ = mockDevtoolsCompose
19
+ const composeWithDevToolsSpy = vi . spyOn ( DevTools , 'composeWithDevTools' )
20
+
21
+ ; ( window as any ) . __REDUX_DEVTOOLS_EXTENSION_COMPOSE__ = composeWithDevToolsSpy
57
22
58
23
const redux = await import ( 'redux' )
59
24
@@ -76,7 +41,7 @@ describe('configureStore', async () => {
76
41
expect . any ( Function )
77
42
)
78
43
expect ( redux . applyMiddleware ) . toHaveBeenCalled ( )
79
- expect ( mockDevtoolsCompose ) . toHaveBeenCalled ( ) // @remap -prod-remove-line
44
+ expect ( composeWithDevToolsSpy ) . toHaveBeenCalled ( ) // @remap -prod-remove-line
80
45
} )
81
46
} )
82
47
@@ -90,7 +55,7 @@ describe('configureStore', async () => {
90
55
expect ( configureStore ( { reducer } ) ) . toBeInstanceOf ( Object )
91
56
expect ( redux . combineReducers ) . toHaveBeenCalledWith ( reducer )
92
57
expect ( redux . applyMiddleware ) . toHaveBeenCalled ( )
93
- expect ( mockDevtoolsCompose ) . toHaveBeenCalled ( ) // @remap -prod-remove-line-line
58
+ expect ( composeWithDevToolsSpy ) . toHaveBeenCalled ( ) // @remap -prod-remove-line-line
94
59
expect ( redux . createStore ) . toHaveBeenCalledWith (
95
60
expect . any ( Function ) ,
96
61
undefined ,
@@ -113,7 +78,7 @@ describe('configureStore', async () => {
113
78
configureStore ( { middleware : ( ) => new Tuple ( ) , reducer } )
114
79
) . toBeInstanceOf ( Object )
115
80
expect ( redux . applyMiddleware ) . toHaveBeenCalledWith ( )
116
- expect ( mockDevtoolsCompose ) . toHaveBeenCalled ( ) // @remap -prod-remove-line-line
81
+ expect ( composeWithDevToolsSpy ) . toHaveBeenCalled ( ) // @remap -prod-remove-line-line
117
82
expect ( redux . createStore ) . toHaveBeenCalledWith (
118
83
reducer ,
119
84
undefined ,
@@ -142,7 +107,7 @@ describe('configureStore', async () => {
142
107
expect . any ( Function ) , // serializableCheck
143
108
expect . any ( Function ) // actionCreatorCheck
144
109
)
145
- expect ( mockDevtoolsCompose ) . toHaveBeenCalled ( ) // @remap -prod-remove-line-line
110
+ expect ( composeWithDevToolsSpy ) . toHaveBeenCalled ( ) // @remap -prod-remove-line-line
146
111
expect ( redux . createStore ) . toHaveBeenCalledWith (
147
112
reducer ,
148
113
undefined ,
@@ -179,7 +144,7 @@ describe('configureStore', async () => {
179
144
configureStore ( { middleware : ( ) => new Tuple ( thank ) , reducer } )
180
145
) . toBeInstanceOf ( Object )
181
146
expect ( redux . applyMiddleware ) . toHaveBeenCalledWith ( thank )
182
- expect ( mockDevtoolsCompose ) . toHaveBeenCalled ( ) // @remap -prod-remove-line-line
147
+ expect ( composeWithDevToolsSpy ) . toHaveBeenCalled ( ) // @remap -prod-remove-line-line
183
148
expect ( redux . createStore ) . toHaveBeenCalledWith (
184
149
reducer ,
185
150
undefined ,
@@ -234,7 +199,7 @@ describe('configureStore', async () => {
234
199
Object
235
200
)
236
201
expect ( redux . applyMiddleware ) . toHaveBeenCalled ( )
237
- expect ( mockDevtoolsCompose ) . toHaveBeenCalledWith ( options ) // @remap -prod-remove-line
202
+ expect ( composeWithDevToolsSpy ) . toHaveBeenCalledWith ( options ) // @remap -prod-remove-line
238
203
expect ( redux . createStore ) . toHaveBeenCalledWith (
239
204
reducer ,
240
205
undefined ,
@@ -247,7 +212,7 @@ describe('configureStore', async () => {
247
212
it ( 'calls createStore with preloadedState' , ( ) => {
248
213
expect ( configureStore ( { reducer } ) ) . toBeInstanceOf ( Object )
249
214
expect ( redux . applyMiddleware ) . toHaveBeenCalled ( )
250
- expect ( mockDevtoolsCompose ) . toHaveBeenCalled ( ) // @remap -prod-remove-line
215
+ expect ( composeWithDevToolsSpy ) . toHaveBeenCalled ( ) // @remap -prod-remove-line
251
216
expect ( redux . createStore ) . toHaveBeenCalledWith (
252
217
reducer ,
253
218
undefined ,
@@ -278,7 +243,7 @@ describe('configureStore', async () => {
278
243
} )
279
244
) . toBeInstanceOf ( Object )
280
245
expect ( redux . applyMiddleware ) . toHaveBeenCalled ( )
281
- expect ( mockDevtoolsCompose ) . toHaveBeenCalled ( ) // @remap -prod-remove-line
246
+ expect ( composeWithDevToolsSpy ) . toHaveBeenCalled ( ) // @remap -prod-remove-line
282
247
expect ( redux . createStore ) . toHaveBeenCalledWith (
283
248
reducer ,
284
249
undefined ,
0 commit comments