Created
April 21, 2018 06:09
-
-
Save coleturner/3d7ed884d86fb1b8c066f1cfb5786afe to your computer and use it in GitHub Desktop.
Quick bootstrapping for testing GraphQL Resolvers
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
// 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'); | |
}; |
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
// 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