diff --git a/Changelog.md b/Changelog.md index 5ef8182cfc..a89e5715b5 100644 --- a/Changelog.md +++ b/Changelog.md @@ -30,6 +30,7 @@ first three params (`TChildProps` can be derived). [#1402](https://github.com/ap - Converted `test/test-utils/test-utils.test.js` to `test/test-utils.test.tsx` [#1475](https://github.com/apollographql/react-apollo/pull/1475) - Updates to `examples/typescript` [#1471](https://github.com/apollographql/react-apollo/pull/1471) - Mutation test cleanup [#1480](https://github.com/apollographql/react-apollo/pull/1480) + - Removed react-native from the test suite [#1451](https://github.com/apollographql/react-apollo/pull/1451) ### 2.0.4 - rolled back on the lodash-es changes from diff --git a/package.json b/package.json index b1a53bef8e..75ededeedc 100644 --- a/package.json +++ b/package.json @@ -49,16 +49,14 @@ ], "author": "James Baxley ", "babel": { - "presets": ["react-native"] + "presets": ["env"] }, "jest": { - "preset": "react-native", "testEnvironment": "jsdom", "transform": { "^.+\\.tsx?$": "ts-jest", "^.+\\.jsx?$": "babel-jest" }, - "transformIgnorePatterns": ["/node_modules/(?!(react-native)/)"], "mapCoverage": true, "moduleFileExtensions": ["ts", "tsx", "js", "json"], "modulePathIgnorePatterns": [ @@ -90,7 +88,6 @@ "babel-core": "6.26.0", "babel-jest": "22.0.4", "babel-preset-env": "1.6.1", - "babel-preset-react-native": "4.0.0", "bundlesize": "0.15.3", "coveralls": "3.0.0", "danger": "2.1.6", @@ -106,7 +103,6 @@ "prettier": "1.9.2", "react": "16.2.0", "react-dom": "16.2.0", - "react-native": "0.51.0", "react-test-renderer": "16.2.0", "recompose": "0.26.0", "rimraf": "2.6.2", diff --git a/test/client/Query.test.tsx b/test/client/Query.test.tsx index 47f351a85b..dcb8c2e1c5 100644 --- a/test/client/Query.test.tsx +++ b/test/client/Query.test.tsx @@ -26,10 +26,17 @@ const allPeopleMocks = [ ]; describe('Query component', () => { + let wrapper; beforeEach(() => { jest.useRealTimers(); }); + afterEach(() => { + if (wrapper) { + wrapper.unmount(); + wrapper = null; + } + }); it('calls the children prop', done => { const Component = () => ( @@ -50,7 +57,7 @@ describe('Query component', () => { ); - mount( + wrapper = mount( , @@ -62,7 +69,7 @@ describe('Query component', () => { {result =>
} ); - const wrapper = mount( + wrapper = mount( , @@ -98,7 +105,7 @@ describe('Query component', () => { ); - mount( + wrapper = mount( , @@ -120,7 +127,7 @@ describe('Query component', () => { ); - mount( + wrapper = mount( , @@ -128,6 +135,20 @@ describe('Query component', () => { }); it('sets the notifyOnNetworkStatusChange prop', done => { + const data1 = { allPeople: { people: [{ name: 'Luke Skywalker' }] } }; + const data2 = { allPeople: { people: [{ name: 'Han Solo' }] } }; + + const mocks = [ + { + request: { query: allPeopleQuery }, + result: { data: data1 }, + }, + { + request: { query: allPeopleQuery }, + result: { data: data2 }, + }, + ]; + let count = 0; expect.assertions(4); const Component = () => ( @@ -158,8 +179,8 @@ describe('Query component', () => { ); - mount( - + wrapper = mount( + , ); @@ -190,30 +211,27 @@ describe('Query component', () => { }, ]; - const render = jest.fn(() => null); - const variables = { first: 1, }; const Component = () => ( - {render} + {result => { + catchAsyncError(done, () => { + expect(result.variables).toEqual({ first: 1 }); + done(); + }); + return null; + }} ); - mount( + wrapper = mount( , ); - - setTimeout(() => { - catchAsyncError(done, () => { - expect(render.mock.calls[0][0].variables).toEqual({ first: 1 }); - done(); - }); - }, 0); }); it('errors if a Mutation is provided in the query', () => { @@ -318,6 +336,7 @@ describe('Query component', () => { count++; return null; } + catchAsyncError(done, () => { if (count === 1) { // first data @@ -365,7 +384,7 @@ describe('Query component', () => { ); - mount( + wrapper = mount( , @@ -436,7 +455,7 @@ describe('Query component', () => { ); - mount( + wrapper = mount( , @@ -489,7 +508,7 @@ describe('Query component', () => { }, ]; - const wrapper = mount( + wrapper = mount( , @@ -499,7 +518,6 @@ describe('Query component', () => { catchAsyncError(done, () => { expect(count).toBe(POLL_COUNT); - wrapper.unmount(); done(); }); }); @@ -559,7 +577,7 @@ describe('Query component', () => { }, ]; - const wrapper = mount( + wrapper = mount( , @@ -569,7 +587,6 @@ describe('Query component', () => { catchAsyncError(done, () => { expect(count).toBe(POLL_COUNT); - wrapper.unmount(); done(); }); }); @@ -619,7 +636,7 @@ describe('Query component', () => { }, ]; - const wrapper = mount( + wrapper = mount( , @@ -629,7 +646,6 @@ describe('Query component', () => { catchAsyncError(done, () => { expect(count).toBe(POLL_COUNT); - wrapper.unmount(); done(); }); }); @@ -684,7 +700,7 @@ describe('Query component', () => { ); - mount( + wrapper = mount( , @@ -763,7 +779,7 @@ describe('Query component', () => { } } - mount( + wrapper = mount( , @@ -836,7 +852,7 @@ describe('Query component', () => { } } - mount( + wrapper = mount( , @@ -886,7 +902,7 @@ describe('Query component', () => { } } - mount( + wrapper = mount( , @@ -952,6 +968,6 @@ describe('Query component', () => { } } - mount(); + wrapper = mount(); }); }); diff --git a/test/client/graphql/queries/observableQuery.test.tsx b/test/client/graphql/queries/observableQuery.test.tsx index a1c6a0300f..6d4542a7af 100644 --- a/test/client/graphql/queries/observableQuery.test.tsx +++ b/test/client/graphql/queries/observableQuery.test.tsx @@ -7,7 +7,6 @@ import { ApolloLink } from 'apollo-link'; import { InMemoryCache as Cache } from 'apollo-cache-inmemory'; import { mockSingleLink } from '../../../../src/test-utils'; import { ApolloProvider, graphql } from '../../../../src'; - import stripSymbols from '../../../test-utils/stripSymbols'; describe('[queries] observableQuery', () => { @@ -217,59 +216,6 @@ describe('[queries] observableQuery', () => { expect(queryObservable1).toBe(queryObservable2); }); - it('will refetch active `ObservableQuery`s when resetting the client store', () => { - const query = gql` - query people { - allPeople(first: 1) { - people { - name - } - } - } - `; - // const data = { allPeople: { people: [{ name: 'Luke Skywalker' }] } }; - let called = 0; - const link = new ApolloLink((o, f) => { - called++; - return f(o); - }).concat( - mockSingleLink( - { - request: { query }, - result: { data: { allPeople: null } }, - }, - { - request: { query }, - result: { data: { allPeople: { people: null } } }, - }, - ), - ); - const client = new ApolloClient({ - link, - cache: new Cache({ addTypename: false }), - }); - - @graphql(query) - class Container extends React.Component { - render() { - return null; - } - } - - renderer.create( - - - , - ); - - const keys = Array.from((client.queryManager as any).queries.keys()); - expect(keys).toEqual(['1']); - expect(called).toBe(1); - (client.resetStore() as Promise).then(() => { - expect(called).toBe(2); - }); - }); - it('will recycle `ObservableQuery`s when re-rendering a portion of the tree', done => { const query = gql` query people { diff --git a/test/react-native/__snapshots__/component.test.tsx.snap b/test/react-native/__snapshots__/component.test.tsx.snap deleted file mode 100644 index 1c2c7ff5f9..0000000000 --- a/test/react-native/__snapshots__/component.test.tsx.snap +++ /dev/null @@ -1,11 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`App renders correctly 1`] = ` - - Loading... - -`; diff --git a/test/react-native/component.test.tsx b/test/react-native/component.test.tsx deleted file mode 100644 index 7100c51503..0000000000 --- a/test/react-native/component.test.tsx +++ /dev/null @@ -1,97 +0,0 @@ -import { Text } from 'react-native'; -import * as React from 'react'; -// Note: test renderer must be required after react-native. -import * as renderer from 'react-test-renderer'; -import ApolloClient from 'apollo-client'; -import { InMemoryCache as Cache } from 'apollo-cache-inmemory'; -import gql from 'graphql-tag'; -import { ApolloProvider, ChildProps, graphql } from '../../src'; -import { mockSingleLink } from '../../src/test-utils'; - -import stripSymbols from '../test-utils/stripSymbols'; - -describe('App', () => { - it('renders correctly', () => { - const query = gql` - query people { - allPeople(first: 1) { - people { - name - } - } - } - `; - - interface Data { - allPeople: { people: { name: string } }; - } - const link = mockSingleLink({ - request: { query }, - result: { data: { allPeople: { people: { name: 'Luke Skywalker' } } } }, - }); - const client = new ApolloClient({ - link, - cache: new Cache({ addTypename: false }), - }); - - const ContainerWithData = graphql(query)( - ({ data }: ChildProps<{}, Data>) => { - if (data.loading) return Loading...; - return {data.allPeople.people.name}; - }, - ); - const output = renderer.create( - - - , - ); - expect(output.toJSON()).toMatchSnapshot(); - }); - - it('executes a query', done => { - jest.useRealTimers(); - const query = gql` - query people { - allPeople(first: 1) { - people { - name - } - } - } - `; - interface Data { - allPeople: { people: { name: string } }; - } - const data1 = { allPeople: { people: { name: 'Luke Skywalker' } } }; - const link = mockSingleLink({ - request: { query }, - result: { data: data1 }, - }); - const client = new ApolloClient({ - link, - cache: new Cache({ addTypename: false }), - }); - - class Container extends React.Component> { - componentWillReceiveProps(props) { - expect(props.data.loading).toBeFalsy(); - expect(stripSymbols(props.data.allPeople.people.name)).toEqual( - data1.allPeople.people.name, - ); - done(); - } - render() { - if (this.props.data.loading) return Loading...; - return {this.props.data.allPeople.people.name}; - } - } - - const ContainerWithData = graphql(query)(Container); - - renderer.create( - - - , - ); - }); -}); diff --git a/test/test-utils/setup.ts b/test/test-utils/setup.ts index ae99b566ff..d03b8e4aa4 100644 --- a/test/test-utils/setup.ts +++ b/test/test-utils/setup.ts @@ -1 +1,2 @@ +import './shim'; import './enzyme'; diff --git a/test/test-utils/shim.ts b/test/test-utils/shim.ts new file mode 100644 index 0000000000..711c93cfe8 --- /dev/null +++ b/test/test-utils/shim.ts @@ -0,0 +1,9 @@ +/** + * React requires the requestAnimationFrame to be defined for tests. + */ +// Prevent typescript from giving error. +const globalAny: any = global; + +globalAny.requestAnimationFrame = callback => { + setTimeout(callback, 0); +};