Skip to content
Permalink
Browse files

test getStartingData in pages/index

  • Loading branch information
levity committed Dec 18, 2019
1 parent d22d4a6 commit 1b4b4f24013bf8771d4f3d939df0047b520d7e24
Showing with 27 additions and 6 deletions.
  1. +16 −4 tests/helpers/render.js
  2. +11 −2 tests/pages/index.spec.js
@@ -9,25 +9,37 @@ import theme from '../../utils/theme';

export default async function render(
children,
{ initialState, getMaker } = {}
{
initialState,
getMaker,

// use this callback to get updates every time the store state changes
storeCallback
} = {}
) {
let storeCallback;
let wrappedStoreCallback;
const storePromise = new Promise(resolve => {
storeCallback = (state, dispatch) => resolve([state, dispatch]);
wrappedStoreCallback = (state, dispatch) => {
if (storeCallback) storeCallback(state, dispatch);
resolve([state, dispatch]);
};
});

const renderResults = renderBase(
<ThemeProvider theme={theme}>
<MakerProvider network="test">
<MakerAccess callback={getMaker}>
<StoreProvider initialState={initialState}>
<StoreAccess callback={storeCallback}>{children}</StoreAccess>
<StoreAccess callback={wrappedStoreCallback}>
{children}
</StoreAccess>
</StoreProvider>
</MakerAccess>
</MakerProvider>
</ThemeProvider>
);

// these values are only valid for the first render
const [state, dispatch] = await storePromise;
return { ...renderResults, state, dispatch };
}
@@ -1,7 +1,16 @@
import Index from '../../pages';
import render from '../helpers/render';
import assert from 'assert';
import { wait } from '@testing-library/react';

test('basic rendering', async () => {
const { getByText } = await render(<Index />);
test('render and get starting data', async () => {
let state;
const { getByText } = await render(<Index />, {
storeCallback: s => {
state = s;
}
});
getByText(/Migrate and Upgrade/);
await wait(() => assert(state.saiAvailable));
getByText(/Sai available for CDP migration/);
});

0 comments on commit 1b4b4f2

Please sign in to comment.
You can’t perform that action at this time.