Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
reset branch
Browse files Browse the repository at this point in the history
  • Loading branch information
James Baxley committed Aug 22, 2016
1 parent f81d9dc commit 5629494
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions test/react-web/server/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,57 @@ describe('SSR', () => {
;
});

it('should not require `ApolloProvider` to be the root component', (done) => {

const query = gql`{ currentUser { firstName } }`;
const data = { currentUser: { firstName: 'James' } };
const networkInterface = mockNetworkInterface(
{ request: { query }, result: { data }, delay: 50 }
);
const apolloClient = new ApolloClient({ networkInterface });

const WrappedElement = graphql(query)(({ data }) => (
<div>{data.loading ? 'loading' : data.currentUser.firstName}</div>
));

class MyRootContainer extends React.Component<any, any> {

constructor(props) {
super(props);
this.state = { color: 'purple' };
}

getChildContext() {
return { color: this.state.color };
}

render() {
return <div>{this.props.children}</div>;
}
}

(MyRootContainer as any).childContextTypes = {
color: React.PropTypes.string,
};

const app = (
<MyRootContainer>
<ApolloProvider client={apolloClient}>
<WrappedElement />
</ApolloProvider>
</MyRootContainer>
);

getDataFromTree(app)
.then(() => {
const markup = ReactDOM.renderToString(app);
expect(markup).to.match(/James/);
done();
})
.catch(done)
;
});

});

describe('`renderToStringWithData`', () => {
Expand Down

0 comments on commit 5629494

Please sign in to comment.