Skip to content

Commit

Permalink
Add a test for undefined variable bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Buryak committed Nov 16, 2022
1 parent a1439db commit 449369a
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,35 @@ describe('getDiagnostics', () => {
expect(error.source).toEqual('GraphQL: Validation');
});

it('validates undefined variables', () => {
const errors = validateQuery(
parse('{ hero(episode: $ep) { name } }'),
schema,
);
expect(errors).toMatchInlineSnapshot(`
Array [
Object {
"message": "Variable \\"$ep\\" is not defined.",
"range": Range {
"containsPosition": [Function],
"end": Position {
"character": 20,
"lessThanOrEqualTo": [Function],
"line": 0,
},
"start": Position {
"character": 16,
"lessThanOrEqualTo": [Function],
"line": 0,
},
},
"severity": 1,
"source": "GraphQL: Validation",
},
]
`);
});

it('catches multi root validation errors without breaking (with a custom validation function that always throws errors)', () => {
const error = validateQuery(parse('{ hero { name } } { seq }'), schema, [
validationContext => {
Expand Down

0 comments on commit 449369a

Please sign in to comment.