Skip to content
This repository was archived by the owner on Sep 2, 2020. It is now read-only.

Improve diagnostics tests #236

Merged
merged 5 commits into from
Jun 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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