Created
October 9, 2017 11:20
-
-
Save javierfernandes/4482429d3a891201b9272682dfbc83b9 to your computer and use it in GitHub Desktop.
describeGraphQL() util method for gql test
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 { graphql } from 'graphql' | |
| import mongoose from 'mongoose' | |
| import { Mockgoose } from 'mockgoose' | |
| import '../../src/models/all' | |
| import { expect } from 'chai' | |
| import { compileSchemas } from '../../src/graphql/utils/compileSchema' | |
| const internalDescribeQL = (describeFn) => (title, body) => { | |
| describeFn(title, () => { | |
| let schema | |
| const mockgoose = new Mockgoose(mongoose); | |
| before(async () => { | |
| await mockgoose.prepareStorage() | |
| await mongoose.connect('mongodb://example.com/TestingDB') | |
| schema = compileSchemas() | |
| }) | |
| after(done => { | |
| mongoose.disconnect(done) | |
| }) | |
| beforeEach(() => { | |
| mockgoose.helper.reset() | |
| }) | |
| const expectQuery = async(query, expected) => { | |
| expect(await graphql(schema, query, undefined, { })).to.deep.equal(expected) | |
| } | |
| const expectQueryResult = (query, expected) => { | |
| return expectQuery(query, { data: expected }) | |
| } | |
| body({ expectQuery, expectQueryResult }, schema) | |
| }) | |
| } | |
| export const describeGQL = internalDescribeQL(describe) | |
| describeGQL.only = internalDescribeQL(describe.only) | |
| describeGQL.skip = internalDescribeQL(describe.skip) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment