Skip to content

Commit 8707555

Browse files
committed
a few additional tests to cover optional cases
1 parent f287b63 commit 8707555

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

package-lock.json

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"eslint-plugin-istanbul": "0.1.2",
6464
"eslint-plugin-node": "11.1.0",
6565
"eslint-plugin-tsdoc": "0.2.14",
66+
"esm": "^3.2.25",
6667
"mocha": "9.1.0",
6768
"nyc": "15.1.0",
6869
"prettier": "2.3.2",

src/language/__tests__/parser-test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,16 @@ describe('Parser', () => {
255255
).to.not.throw();
256256
});
257257

258+
it('parses optional with alias', () => {
259+
expect(() =>
260+
parse(`
261+
query {
262+
requiredField: field?
263+
}
264+
`),
265+
).to.not.throw();
266+
});
267+
258268
it('does not parse aliased field with bang on left of colon', () => {
259269
expect(() =>
260270
parse(`
@@ -265,6 +275,16 @@ describe('Parser', () => {
265275
).to.throw();
266276
});
267277

278+
it('does not parse aliased field with question mark on left of colon', () => {
279+
expect(() =>
280+
parse(`
281+
query {
282+
requiredField?: field
283+
}
284+
`),
285+
).to.throw();
286+
});
287+
268288
it('does not parse aliased field with bang on left and right of colon', () => {
269289
expect(() =>
270290
parse(`
@@ -275,6 +295,16 @@ describe('Parser', () => {
275295
).to.throw();
276296
});
277297

298+
it('does not parse aliased field with question mark on left and right of colon', () => {
299+
expect(() =>
300+
parse(`
301+
query {
302+
requiredField?: field?
303+
}
304+
`),
305+
).to.throw();
306+
});
307+
278308
it('parses required within fragment', () => {
279309
expect(() =>
280310
parse(`
@@ -285,6 +315,16 @@ describe('Parser', () => {
285315
).to.not.throw();
286316
});
287317

318+
it('parses optional within fragment', () => {
319+
expect(() =>
320+
parse(`
321+
fragment MyFragment on Query {
322+
field?
323+
}
324+
`),
325+
).to.not.throw();
326+
});
327+
288328
it('creates ast', () => {
289329
const result = parse(dedent`
290330
{

0 commit comments

Comments
 (0)