Skip to content

Commit

Permalink
test issue 115
Browse files Browse the repository at this point in the history
  • Loading branch information
morrys committed Sep 24, 2020
1 parent d9d0942 commit ce305c3
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions __tests__/usePreloadQuery-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -749,5 +749,54 @@ describe('usePreloadQuery', () => {
TestRenderer.act(() => jest.runAllImmediates());
expect(renderer.toJSON()).toEqual('Error Boundary');
});

it('issue-115', () => {
prefetched.next(environment, params, { id: '4' });

let data;
function Component(props) {
data = usePreloadedQuery(props.prefetched);
if (data.error) {
return 'Error Boundary';
}
if (data.props && data.props.node) {
return data.props.node.name;
}
return data.props;
}
const renderer = TestRenderer.create(
<RelayEnvironmentProvider environment={environment}>
<Component prefetched={prefetched} />
</RelayEnvironmentProvider>,
);
// Ensure that useEffect runs
TestRenderer.act(() => jest.runAllImmediates());
expect(renderer.toJSON()).toEqual(null);
expect(data).toEqual(loadingData);

dataSource.next(response);
dataSource.complete();
TestRenderer.act(() => jest.runAllImmediates());
expect(renderer.toJSON()).toEqual('Zuck');
expect(data.props).toEqual({
node: {
id: '4',
name: 'Zuck',
},
});

TestRenderer.act(() => renderer.unmount());
TestRenderer.act(() => jest.runAllImmediates());
prefetched.next(environment, params, { id: '4' });
dataSource.next(response);
dataSource.complete();
TestRenderer.act(() => jest.runAllImmediates());
expect((prefetched.getValue(environment) as any).props).toEqual({
node: {
id: '4',
name: 'Zuck',
},
});
});
});
});

0 comments on commit ce305c3

Please sign in to comment.