@@ -16,6 +16,7 @@ import { ThemeProvider } from 'styled-components'
16
16
import { themeLight } from '@redis-ui/styles'
17
17
import userEvent from '@testing-library/user-event'
18
18
import type { RootState , ReduxStore } from 'uiSrc/slices/store'
19
+ import { setStoreRef } from 'uiSrc/slices/store-dynamic'
19
20
import { initialState as initialStateInstances } from 'uiSrc/slices/instances/instances'
20
21
import { initialState as initialStateTags } from 'uiSrc/slices/instances/tags'
21
22
import { initialState as initialStateCaCerts } from 'uiSrc/slices/instances/caCerts'
@@ -168,6 +169,10 @@ export const mockStore = configureMockStore<RootState>([thunk])
168
169
export const mockedStore = mockStore ( initialStateDefault )
169
170
export const mockedStoreFn = ( ) => mockStore ( initialStateDefault )
170
171
172
+ // Set the mock store reference for the dynamic store wrapper
173
+ // This ensures that store-dynamic works correctly in tests
174
+ setStoreRef ( mockedStore as any )
175
+
171
176
// insert root state to the render Component
172
177
const render = (
173
178
ui : JSX . Element ,
@@ -178,6 +183,11 @@ const render = (
178
183
...renderOptions
179
184
} : Options = initialStateDefault ,
180
185
) => {
186
+ // Set the store reference for the dynamic store wrapper if a custom store is provided
187
+ if ( store !== mockedStore ) {
188
+ setStoreRef ( store as any )
189
+ }
190
+
181
191
const Wrapper = ( { children } : { children : JSX . Element } ) => (
182
192
< ThemeProvider theme = { themeLight } >
183
193
< Provider store = { store } > { children } </ Provider >
@@ -198,6 +208,11 @@ const renderHook = (
198
208
...renderOptions
199
209
} : Options = initialStateDefault ,
200
210
) => {
211
+ // Set the store reference for the dynamic store wrapper if a custom store is provided
212
+ if ( store !== mockedStore ) {
213
+ setStoreRef ( store as any )
214
+ }
215
+
201
216
const Wrapper = ( { children } : { children : JSX . Element } ) => (
202
217
< Provider store = { store } > { children } </ Provider >
203
218
)
0 commit comments