Skip to content

Instantly share code, notes, and snippets.

@coleturner
Created April 21, 2018 06:09
Show Gist options
  • Save coleturner/3d7ed884d86fb1b8c066f1cfb5786afe to your computer and use it in GitHub Desktop.
Save coleturner/3d7ed884d86fb1b8c066f1cfb5786afe to your computer and use it in GitHub Desktop.
Quick bootstrapping for testing GraphQL Resolvers
// graphql/types/Animal/Animal.test.js
import * as AnimalResolvers from './Animal.resolvers.js';
export const animalNameTest = () => {
const obj = {
kind: 'Dog',
name: 'Koko',
breeds: ['Corgi', 'German Shepherd']
};
const args = {};
const ctx = {};
const output = AnimalResolvers.name(obj, args, ctx);
expect(output).toEqual('Koko');
};
// graphql/types/resolvers.test.js
import glob from 'glob';
import path from 'path';
const basePath = path.join(process.cwd(), './graphql/types/');
describe('Resolvers', () => {
// Find all our resolver files
const files = glob.sync(`${basePath}**/*.test.js`);
files.forEach(file => {
describe(file, () => {
const resolvers = require(file);
Object.entries(resolvers).forEach(([name, fn]) => {
it(name, () => Promise.resolve(fn()));
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment