@@ -3,16 +3,26 @@ import setupStore from "..";
3
3
describe ( "store" , ( ) => {
4
4
const ORIGINAL_NODE_ENV = process . env . NODE_ENV ;
5
5
6
+ const fetchContext = jest . fn ( ) ;
7
+ const mockRouter = { navigate : jest . fn ( ) } ;
8
+
9
+ beforeAll ( ( ) => {
10
+ mockRouter . navigate . mockClear ( ) ;
11
+ fetchContext . mockClear ( ) ;
12
+ } ) ;
13
+
6
14
afterAll ( ( ) => {
7
15
process . env . NODE_ENV = ORIGINAL_NODE_ENV ;
8
16
delete top . __REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ;
9
17
delete global . BUILD_ID ;
10
18
} ) ;
11
19
12
20
it ( "initialises properly" , async ( ) => {
13
- const fetchContext = jest . fn ( ) ;
14
- const store = await setupStore ( fetchContext ) ;
21
+ const store = await setupStore ( mockRouter , fetchContext ) ;
15
22
expect ( store ) . toBeDefined ( ) ;
23
+
24
+ expect ( fetchContext ) . toHaveBeenCalled ( ) ;
25
+ expect ( mockRouter . navigate ) . toHaveBeenCalled ( ) ;
16
26
} ) ;
17
27
18
28
it ( "accepts middlewares provided via bootstrap" , async ( ) => {
@@ -21,8 +31,7 @@ describe("store", () => {
21
31
spy ( action ) ;
22
32
return next ( action ) ;
23
33
} ;
24
- const fetchContext = jest . fn ( ) ;
25
- const store = await setupStore ( fetchContext , [ customMiddleware ] ) ;
34
+ const store = await setupStore ( mockRouter , fetchContext , [ customMiddleware ] ) ;
26
35
expect ( store ) . toBeDefined ( ) ;
27
36
28
37
const action = { type : "test-probe" } ;
@@ -36,7 +45,7 @@ describe("store", () => {
36
45
top . __REDUX_DEVTOOLS_EXTENSION_COMPOSE__ . mockReturnValue ( ( ) => { } ) ;
37
46
process . env . NODE_ENV = "development" ;
38
47
const fetchContext = jest . fn ( ) ;
39
- const store = await setupStore ( fetchContext , [ ] ) ;
48
+ const store = await setupStore ( mockRouter , fetchContext , [ ] ) ;
40
49
expect ( store ) . toBeDefined ( ) ;
41
50
expect ( top . __REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ) . toHaveBeenCalledWith ( expect . objectContaining ( { name : "rocker-xxx" } ) ) ;
42
51
} ) ;
0 commit comments