All files / src test-utils.tsx

100% Statements 17/17
100% Branches 6/6
100% Functions 3/3
100% Lines 15/15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 3323x 23x 23x   23x 23x 23x   23x       46x 46x   45x 45x 45x             23x 46x           23x  
import * as React from 'react';
import ApolloClient from 'apollo-client';
import { InMemoryCache as Cache } from 'apollo-cache-inmemory';
 
import { ApolloProvider } from './';
import { mockSingleLink } from './test-links';
export * from './test-links';
 
export class MockedProvider extends React.Component<any, any> {
  private client: any;
 
  constructor(props: any, context: any) {
    super(props, context);
    if (this.props.client) return;
 
    const addTypename = !this.props.removeTypename;
    const link = mockSingleLink.apply(null, this.props.mocks);
    this.client = new ApolloClient({
      link,
      cache: new Cache({ addTypename }),
      defaultOptions: this.props.defaultOptions,
    });
  }
 
  render() {
    return (
      <ApolloProvider client={this.client || this.props.client}>
        {this.props.children}
      </ApolloProvider>
    );
  }
}