1
+ import React from 'react' ;
2
+ import { render as rtlRender , screen } from '@testing-library/react' ;
3
+ import '@testing-library/jest-dom/extend-expect' ;
4
+ import MainSlider from '../components/MainSlider' ;
5
+ import { mainSlice } from '../RTKslices'
6
+ import { Provider } from 'react-redux' ;
7
+ import { configureStore } from '@reduxjs/toolkit' ;
8
+
9
+
10
+ const customTabs = {
11
+ 100 : {
12
+ sliderIndex : 1 ,
13
+ } ,
14
+ }
15
+
16
+
17
+ const customInitialState = {
18
+ main : {
19
+ port : null ,
20
+ currentTab : 87 ,
21
+ currentTitle : null ,
22
+ tabs : customTabs , // Replace with the actual (testing) tab data
23
+ currentTabInApp : null ,
24
+ connectionStatus : false ,
25
+ connectRequested : true ,
26
+ } ,
27
+ } ;
28
+
29
+ const customStore = configureStore ( {
30
+ reducer : {
31
+ main : mainSlice . reducer ,
32
+ } ,
33
+ preloadedState : customInitialState ,
34
+ middleware : ( getDefaultMiddleware ) =>
35
+ getDefaultMiddleware ( { serializableCheck : false } ) ,
36
+ } ) ;
37
+
38
+ const render = component => rtlRender (
39
+ < Provider store = { customStore } >
40
+ { component }
41
+ </ Provider >
42
+ ) ;
43
+
44
+ jest . mock ( 'react-redux' , ( ) => ( {
45
+ ...jest . requireActual ( 'react-redux' ) , // Use the actual react-redux module except for the functions you want to mock
46
+ useDispatch : jest . fn ( ) , // set up a mock function for useDispatch
47
+ } ) ) ;
0 commit comments