Skip to content

Commit

Permalink
Improve diagnostics tests (#236)
Browse files Browse the repository at this point in the history
* fix: typo in language service test

* tests: add more cases to getDiagnostics

* tests: improvements in diagnostics service test cases

* use: npm run prettier
  • Loading branch information
Divyendu Singh authored and asiandrummer committed Jun 3, 2018
1 parent 1e161ea commit f37d147
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,9 @@ describe('GraphQLLanguageService', () => {
'./queries/testQuery.graphql',
);
expect(diagnostics.length).to.equal(1);
const diagnostic = diagnostics[0];
expect(diagnostic.message).to.equal(
'Syntax Error: Unexpected Name "qeury"',
);
});
});
30 changes: 30 additions & 0 deletions packages/interface/src/__tests__/getDiagnostics-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,36 @@ describe('getDiagnostics', () => {
expect(error.source).to.equal('GraphQL: Deprecation');
});

it('returns no errors for valid query', () => {
const errors = getDiagnostics('query { hero { name } }', schema);
expect(errors.length).to.equal(0);
});

it('returns no errors for valid query with aliases', () => {
const errors = getDiagnostics(
'query { superHero: hero { superName: name } superHero2: hero { superName2: name } }',
schema,
);
expect(errors.length).to.equal(0);
});

it('catches a syntax error in the SDL', () => {
const errors = getDiagnostics(
`
type Human implements Character {
field_without_type_is_a_syntax_error
id: String!
}
`,
schema,
);
expect(errors.length).to.equal(1);
const error = errors[0];
expect(error.message).to.equal('Syntax Error: Expected :, found Name "id"');
expect(error.severity).to.equal(SEVERITY.ERROR);
expect(error.source).to.equal('GraphQL: Syntax');
});

// TODO: change this kitchen sink to depend on the local schema
// and then run diagnostics with the schema
it('returns no errors after parsing kitchen-sink query', () => {
Expand Down

0 comments on commit f37d147

Please sign in to comment.