Skip to content

Instantly share code, notes, and snippets.

@gufranmirza
Created June 25, 2019 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gufranmirza/c933a05cac0fe325e7b3701c2f74bb64 to your computer and use it in GitHub Desktop.
Save gufranmirza/c933a05cac0fe325e7b3701c2f74bb64 to your computer and use it in GitHub Desktop.
'use strict'
const fs = require('fs')
const path = require('path')
const { expect } = require('chai')
const EasyGraphQLTester = require('../lib')
const schemaCode = fs.readFileSync(path.join(__dirname, 'schema', 'schema.gql'), 'utf8')
describe('Mutation', () => {
let tester
before(() => {
tester = new EasyGraphQLTester(schemaCode)
})
describe('Should throw an error if variables are missing', () => {
it('Should throw an error if the variables are missing', () => {
let error
try {
const mutation = `
mutation CreateUser{
createUser {
email
}
}
`
tester.mock(mutation)
} catch (err) {
error = err
}
expect(error).to.be.an.instanceOf(Error)
expect(error.message).to.be.eq('Variables are missing')
})
})
describe('Should return selected fields', () => {
it('Should return selected fields', () => {
const mutation = `
mutation CreateUser{
createUser {
email
}
}
`
const test = tester.mock(mutation, {
email: 'test@test.com',
username: 'test',
fullName: 'test',
password: 'test'
})
expect(test).to.exist
expect(test.email).to.be.a('string')
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment