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

Commit f37d147

Browse files
Divyendu Singhasiandrummer
authored andcommitted
Improve diagnostics tests (#236)
* fix: typo in language service test * tests: add more cases to getDiagnostics * tests: improvements in diagnostics service test cases * use: npm run prettier
1 parent 1e161ea commit f37d147

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

packages/interface/src/__tests__/GraphQLLanguageService-test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,9 @@ describe('GraphQLLanguageService', () => {
3737
'./queries/testQuery.graphql',
3838
);
3939
expect(diagnostics.length).to.equal(1);
40+
const diagnostic = diagnostics[0];
41+
expect(diagnostic.message).to.equal(
42+
'Syntax Error: Unexpected Name "qeury"',
43+
);
4044
});
4145
});

packages/interface/src/__tests__/getDiagnostics-test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,36 @@ describe('getDiagnostics', () => {
4747
expect(error.source).to.equal('GraphQL: Deprecation');
4848
});
4949

50+
it('returns no errors for valid query', () => {
51+
const errors = getDiagnostics('query { hero { name } }', schema);
52+
expect(errors.length).to.equal(0);
53+
});
54+
55+
it('returns no errors for valid query with aliases', () => {
56+
const errors = getDiagnostics(
57+
'query { superHero: hero { superName: name } superHero2: hero { superName2: name } }',
58+
schema,
59+
);
60+
expect(errors.length).to.equal(0);
61+
});
62+
63+
it('catches a syntax error in the SDL', () => {
64+
const errors = getDiagnostics(
65+
`
66+
type Human implements Character {
67+
field_without_type_is_a_syntax_error
68+
id: String!
69+
}
70+
`,
71+
schema,
72+
);
73+
expect(errors.length).to.equal(1);
74+
const error = errors[0];
75+
expect(error.message).to.equal('Syntax Error: Expected :, found Name "id"');
76+
expect(error.severity).to.equal(SEVERITY.ERROR);
77+
expect(error.source).to.equal('GraphQL: Syntax');
78+
});
79+
5080
// TODO: change this kitchen sink to depend on the local schema
5181
// and then run diagnostics with the schema
5282
it('returns no errors after parsing kitchen-sink query', () => {

0 commit comments

Comments
 (0)