Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apollo-mocknetworkinterface

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-mocknetworkinterface

Network interface for mocking. See README.md for more information.

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

apollo-mocknetworkinterface

npm version

Supports both Apollo 1 & Apollo 2

Installation

To install the stable version:

npm install --save apollo-mocknetworkinterface@^1.0

What is the purpose of the package?

Please read https://medium.com/p/ef0bbd17e686

Example

import React from 'react';
import { ApolloClient, ApolloProvider, graphql } from 'react-apollo';
import renderer from 'react-test-renderer';
import MockNetworkInterface from 'apollo-mocknetworkinterface';
import query from './query.graphql';

const TestComponent = (props) => {
  if (props.data.loading) {
    return (<div>loading ... {JSON.stringify(props)}</div>);
  }
  return (<div>got data ... {JSON.stringify(props)}</div>);
};
const TestComponentWithApollo = graphql(query, {
  options: props => ({
    variables: { url: props.url },
  }),
})(TestComponent);

const createResponse = (request) => { // pure function returning data
  console.log('creating mocked response for request:', request); // eslint-disable-line no-console
  // will log: creating mocked response for request: { query: { kind: 'Document' ...
  return {
    data: {
      component: {
        id: 1,
        name: 'foo',
      },
    },
  };
};
const mockedNetworkFetch = createMockedNetworkFetch(createResponse, { timeout: 100 }); // you can simulate network latency
const client = new ApolloClient({
  link: createHttpLink({ uri: 'http://localhost:3000', fetch: mockedNetworkFetch }),
  cache: new InMemoryCache(),
});

it('should render without exploding', (done) => {
  const component = renderer.create((
    <ApolloProvider client={client}>
      <div>
        <TestComponentWithApollo />
      </div>
    </ApolloProvider>
  ));
})

Keywords

FAQs

Package last updated on 23 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc