Skip to content

Instantly share code, notes, and snippets.

@philsch
Created June 7, 2019 08:19
Show Gist options
  • Save philsch/4dd6551f1d1348abd76bbe81601ea07a to your computer and use it in GitHub Desktop.
Save philsch/4dd6551f1d1348abd76bbe81601ea07a to your computer and use it in GitHub Desktop.
Blogpost: Easy integration testing of GraphQL with Jest
import * as util from 'util';
import * as rp from 'request-promise';
import { exec } from 'child_process';
const pExec = util.promisify(exec);
const API = 'http://localhost:4466/';
const CMD_SEED_DATABASE = `${__dirname}/../seed.sh`;
describe('Getting shop items', () => {
beforeAll(async () => {
await pExec(CMD_SEED_DATABASE);
});
it('Retrieves the shop items in default order', async () => {
const query = `
query {
shopItems {
name
category
size
}
}
`;
const response = await rp({method: 'POST', uri: API, body: {query}, json: true});
expect(response).toMatchSnapshot();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment