Skip to content

Commit

Permalink
Fix fetch mocking in Apollo test (#622)
Browse files Browse the repository at this point in the history
* Fix fetch mocking in Apollo test

* Add babel-cli dev dep to Apollo example

* Remove node-fetch from ApolloProxy's dev deps
  • Loading branch information
ovidiuch authored and xavxyz committed Mar 17, 2018
1 parent 3a85661 commit e3052ea
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
5 changes: 4 additions & 1 deletion examples/apollo/package.json
Expand Up @@ -23,5 +23,8 @@
"react-cosmos-shared": "^3.6.1"
},
"xo": false,
"private": true
"private": true,
"devDependencies": {
"babel-cli": "^6.26.0"
}
}
3 changes: 1 addition & 2 deletions packages/react-cosmos-apollo-proxy/package.json
Expand Up @@ -21,7 +21,6 @@
"devDependencies": {
"async-until": "^1.0.0",
"fetch-mock": "^5.12.2",
"graphql-tag": "^2.8.0",
"node-fetch": "^2.0.0"
"graphql-tag": "^2.8.0"
}
}
19 changes: 17 additions & 2 deletions packages/react-cosmos-apollo-proxy/src/__tests__/client.js
Expand Up @@ -5,7 +5,6 @@ import { InMemoryCache, ID_KEY } from 'apollo-cache-inmemory';
import { HttpLink } from 'apollo-link-http';
import { graphql } from 'react-apollo';
import gql from 'graphql-tag';
import fetch from 'node-fetch';
import fetchMock from 'fetch-mock';
import until from 'async-until';
import createApolloProxy from '../index';
Expand Down Expand Up @@ -43,7 +42,7 @@ const sampleFixture = {
};

// used under the hood by HttpLink
global.fetch = fetch;
global.fetch = fetchMock.fetchMock;

// render the component fixture
const LastProxy = ({ fixture }) => <fixture.component {...fixture.props} />;
Expand Down Expand Up @@ -96,8 +95,24 @@ describe('proxy not configured', () => {
});

describe('proxy configured with a client', () => {
const resolveWith = {
author: {
__typename: 'Author',
id: 1,
firstName: 'Jane Dough',
[ID_KEY]: 'Author:1'
}
};
let client;

beforeAll(() => {
fetchMock.post('https://xyz', { data: resolveWith });
});

afterEach(() => {
fetchMock.reset();
});

beforeEach(() => {
client = new ApolloClient({
cache: new InMemoryCache(),
Expand Down
4 changes: 0 additions & 4 deletions yarn.lock
Expand Up @@ -7239,10 +7239,6 @@ node-fetch@^1.0.1, node-fetch@^1.3.3:
encoding "^0.1.11"
is-stream "^1.0.1"

node-fetch@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.0.0.tgz#982bba43ecd4f2922a29cc186a6bbb0bb73fcba6"

node-int64@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b"
Expand Down

0 comments on commit e3052ea

Please sign in to comment.