Skip to content

Commit

Permalink
Add test for failure case of unnamed queries
Browse files Browse the repository at this point in the history
  • Loading branch information
nhunzaker committed Sep 8, 2017
1 parent 845c0d1 commit 99c2ebe
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/unnamed-query-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { transform } from 'babel-core';
import assert from 'assert';

const fixture = "gql`type Widget { name: String } query {widget}`";

describe("When given an unnamed query", () => {
let originalError;

before(function() {
originalError = console.error;
});

after(function() {
console.error = originalError;
});

it('fails when there are other definitions', () => {
const calls = [];

console.error = (...args) => calls.push(args.join(' '));

transform(fixture, {
plugins: [['./src']]
});

assert.equal(calls.length, 1);
assert.equal(calls[0], 'error Error: GraphQL query must have name.');
});
});

0 comments on commit 99c2ebe

Please sign in to comment.