From 5629494c0862810ee5f76b5a86d2ece52d00abe9 Mon Sep 17 00:00:00 2001 From: James Baxley Date: Mon, 22 Aug 2016 19:56:22 -0400 Subject: [PATCH] reset branch --- test/react-web/server/index.tsx | 51 +++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/test/react-web/server/index.tsx b/test/react-web/server/index.tsx index 81e7f8ad65..4993f3c48b 100644 --- a/test/react-web/server/index.tsx +++ b/test/react-web/server/index.tsx @@ -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 }) => ( +
{data.loading ? 'loading' : data.currentUser.firstName}
+ )); + + class MyRootContainer extends React.Component { + + constructor(props) { + super(props); + this.state = { color: 'purple' }; + } + + getChildContext() { + return { color: this.state.color }; + } + + render() { + return
{this.props.children}
; + } + } + + (MyRootContainer as any).childContextTypes = { + color: React.PropTypes.string, + }; + + const app = ( + + + + + + ); + + getDataFromTree(app) + .then(() => { + const markup = ReactDOM.renderToString(app); + expect(markup).to.match(/James/); + done(); + }) + .catch(done) + ; + }); + }); describe('`renderToStringWithData`', () => {