This repository was archived by the owner on Feb 5, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +27
-6
lines changed Expand file tree Collapse file tree 2 files changed +27
-6
lines changed Original file line number Diff line number Diff line change @@ -9,25 +9,37 @@ import theme from '../../utils/theme';
9
9
10
10
export default async function render (
11
11
children ,
12
- { initialState, getMaker } = { }
12
+ {
13
+ initialState,
14
+ getMaker,
15
+
16
+ // use this callback to get updates every time the store state changes
17
+ storeCallback
18
+ } = { }
13
19
) {
14
- let storeCallback ;
20
+ let wrappedStoreCallback ;
15
21
const storePromise = new Promise ( resolve => {
16
- storeCallback = ( state , dispatch ) => resolve ( [ state , dispatch ] ) ;
22
+ wrappedStoreCallback = ( state , dispatch ) => {
23
+ if ( storeCallback ) storeCallback ( state , dispatch ) ;
24
+ resolve ( [ state , dispatch ] ) ;
25
+ } ;
17
26
} ) ;
18
27
19
28
const renderResults = renderBase (
20
29
< ThemeProvider theme = { theme } >
21
30
< MakerProvider network = "test" >
22
31
< MakerAccess callback = { getMaker } >
23
32
< StoreProvider initialState = { initialState } >
24
- < StoreAccess callback = { storeCallback } > { children } </ StoreAccess >
33
+ < StoreAccess callback = { wrappedStoreCallback } >
34
+ { children }
35
+ </ StoreAccess >
25
36
</ StoreProvider >
26
37
</ MakerAccess >
27
38
</ MakerProvider >
28
39
</ ThemeProvider >
29
40
) ;
30
41
42
+ // these values are only valid for the first render
31
43
const [ state , dispatch ] = await storePromise ;
32
44
return { ...renderResults , state, dispatch } ;
33
45
}
Original file line number Diff line number Diff line change 1
1
import Index from '../../pages' ;
2
2
import render from '../helpers/render' ;
3
+ import assert from 'assert' ;
4
+ import { wait } from '@testing-library/react' ;
3
5
4
- test ( 'basic rendering' , async ( ) => {
5
- const { getByText } = await render ( < Index /> ) ;
6
+ test ( 'render and get starting data' , async ( ) => {
7
+ let state ;
8
+ const { getByText } = await render ( < Index /> , {
9
+ storeCallback : s => {
10
+ state = s ;
11
+ }
12
+ } ) ;
6
13
getByText ( / M i g r a t e a n d U p g r a d e / ) ;
14
+ await wait ( ( ) => assert ( state . saiAvailable ) ) ;
15
+ getByText ( / S a i a v a i l a b l e f o r C D P m i g r a t i o n / ) ;
7
16
} ) ;
You can’t perform that action at this time.
0 commit comments