This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // src/server.js | |
| context: ({ req }) => { | |
| // pass the request information through to the model | |
| return { | |
| user, | |
| models: { | |
| User: generateUserModel({ req }), | |
| ... | |
| } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react'; | |
| import gql from 'graphql-tag'; | |
| import { Query } from 'react-apollo'; | |
| // Make sure the query is also exported -- not just the component | |
| export const GET_DOG_QUERY = gql` | |
| query getDog($name: String) { | |
| dog(name: $name) { | |
| id | |
| name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Broken because it's missing Apollo Client in the context | |
| it('should render without error', () => { | |
| renderer.create(<Dog name="Buck" />); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Not predictable | |
| it('renders without error', () => { | |
| renderer.create( | |
| <ApolloProvider client={client}> | |
| <Dog name="Buck" /> | |
| </ApolloProvider>, | |
| ); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // dog.test.js | |
| import { MockedProvider } from 'react-apollo/test-utils'; | |
| // The component AND the query need to be exported | |
| import { GET_DOG_QUERY, Dog } from './dog'; | |
| const mocks = [ | |
| { | |
| request: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| it('should render loading state initially', () => { | |
| const component = renderer.create( | |
| <MockedProvider mocks={[]}> | |
| <Dog /> | |
| </MockedProvider>, | |
| ); | |
| const tree = component.toJSON(); | |
| expect(tree.children).toContain('Loading...'); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const wait = require('waait'); | |
| it('should render dog', async () => { | |
| const dogMock = { | |
| request: { | |
| query: GET_DOG_QUERY, | |
| variables: { name: 'Buck' }, | |
| }, | |
| result: { | |
| data: { dog: { id: 1, name: 'Buck', breed: 'poodle' } }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| it('should show error UI', async () => { | |
| const dogMock = { | |
| request: { | |
| query: GET_DOG_QUERY, | |
| variables: { name: 'Buck' }, | |
| }, | |
| error: new Error('aw shucks'), | |
| }; | |
| const component = renderer.create( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const DELETE_DOG_MUTATION = gql` | |
| mutation deleteDog($name: String!) { | |
| deleteDog(name: $name) { | |
| id | |
| name | |
| breed | |
| } | |
| } | |
| `; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import DeleteButton, { DELETE_DOG_MUTATION } from './delete-dog'; | |
| it('should render without error', () => { | |
| renderer.create( | |
| <MockedProvider mocks={[]}> | |
| <DeleteButton /> | |
| </MockedProvider>, | |
| ); | |
| }); |