Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.

Commit 1b4b4f2

Browse files
committed
test getStartingData in pages/index
1 parent d22d4a6 commit 1b4b4f2

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

tests/helpers/render.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,37 @@ import theme from '../../utils/theme';
99

1010
export default async function render(
1111
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+
} = {}
1319
) {
14-
let storeCallback;
20+
let wrappedStoreCallback;
1521
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+
};
1726
});
1827

1928
const renderResults = renderBase(
2029
<ThemeProvider theme={theme}>
2130
<MakerProvider network="test">
2231
<MakerAccess callback={getMaker}>
2332
<StoreProvider initialState={initialState}>
24-
<StoreAccess callback={storeCallback}>{children}</StoreAccess>
33+
<StoreAccess callback={wrappedStoreCallback}>
34+
{children}
35+
</StoreAccess>
2536
</StoreProvider>
2637
</MakerAccess>
2738
</MakerProvider>
2839
</ThemeProvider>
2940
);
3041

42+
// these values are only valid for the first render
3143
const [state, dispatch] = await storePromise;
3244
return { ...renderResults, state, dispatch };
3345
}

tests/pages/index.spec.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
import Index from '../../pages';
22
import render from '../helpers/render';
3+
import assert from 'assert';
4+
import { wait } from '@testing-library/react';
35

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+
});
613
getByText(/Migrate and Upgrade/);
14+
await wait(() => assert(state.saiAvailable));
15+
getByText(/Sai available for CDP migration/);
716
});

0 commit comments

Comments
 (0)