Created
May 1, 2018 01:56
-
-
Save JakeDawkins/84d810d96cc1b36ed270bc09ba148816 to your computer and use it in GitHub Desktop.
Example of integration testing a GraphQL schema
This file contains 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 { schema } from '../my-schema'; | |
// Docs for `graphql` function | |
// http://graphql.org/graphql-js/graphql/#graphql | |
import { graphql } from 'graphql'; | |
it('executes a query that looks up some data', async () => { | |
// optionally create some fake context (i.e. data connectors) | |
const myFakeContext = { restConnectionOne: { findOne: jest.fn() } }; | |
const expectedResult = {...}; | |
const result = await graphql(schema, query, {}, myFakeContext); | |
expect(result.data).toEqual(expectedResult); | |
expect(myFakeContext.restConnectionOne.findOne).toBeCalledWith({ id: 1 }); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment