@@ -4,6 +4,7 @@ import { expect } from 'chai';
44import { describe , it } from 'mocha' ;
55
66import dedent from '../../jsutils/dedent' ;
7+ import invariant from '../../jsutils/invariant' ;
78
89import { parse } from '../../language/parser' ;
910import { Source } from '../../language/source' ;
@@ -61,10 +62,7 @@ function lexValue(str) {
6162 const lexer = createLexer ( new Source ( str ) ) ;
6263 const value = lexer . advance ( ) . value ;
6364
64- /* istanbul ignore if */
65- if ( lexer . advance ( ) . kind !== '<EOF>' ) {
66- throw new Error ( 'Expected EOF' ) ;
67- }
65+ invariant ( lexer . advance ( ) . kind === '<EOF>' , 'Expected EOF' ) ;
6866 return value ;
6967}
7068
@@ -81,25 +79,25 @@ function expectStripped(docString) {
8179 toEqual ( expected ) {
8280 const stripped = stripIgnoredCharacters ( docString ) ;
8381
84- /* istanbul ignore if */
85- if ( stripped !== expected ) {
86- throw new Error ( dedent `
82+ invariant (
83+ stripped === expected ,
84+ dedent `
8785 Expected stripIgnoredCharacters(${ inspectStr ( docString ) } )
8886 to equal ${ inspectStr ( expected ) }
8987 but got ${ inspectStr ( stripped ) }
90- ` ) ;
91- }
88+ ` ,
89+ ) ;
9290
9391 const strippedTwice = stripIgnoredCharacters ( stripped ) ;
9492
95- /* istanbul ignore if */
96- if ( stripped !== strippedTwice ) {
97- throw new Error ( dedent `
93+ invariant (
94+ stripped === strippedTwice ,
95+ dedent `
9896 Expected stripIgnoredCharacters(${ inspectStr ( stripped ) } )
9997 to equal ${ inspectStr ( stripped ) }
10098 but got ${ inspectStr ( strippedTwice ) }
101- ` ) ;
102- }
99+ ` ,
100+ ) ;
103101 } ,
104102 toStayTheSame ( ) {
105103 this . toEqual ( docString ) ;
@@ -414,14 +412,14 @@ describe('stripIgnoredCharacters', () => {
414412 const strippedStr = stripIgnoredCharacters ( blockStr ) ;
415413 const strippedValue = lexValue ( strippedStr ) ;
416414
417- /* istanbul ignore if */
418- if ( originalValue !== strippedValue ) {
419- throw new Error ( dedent `
420- Expected lextOne(stripIgnoredCharacters(${ inspectStr ( blockStr ) } ))
421- to equal ${ inspectStr ( originalValue ) }
422- but got ${ inspectStr ( strippedValue ) }
423- ` ) ;
424- }
415+ invariant (
416+ originalValue === strippedValue ,
417+ dedent `
418+ Expected lextOne(stripIgnoredCharacters(${ inspectStr ( blockStr ) } ))
419+ to equal ${ inspectStr ( originalValue ) }
420+ but got ${ inspectStr ( strippedValue ) }
421+ ` ,
422+ ) ;
425423 return expectStripped ( blockStr ) ;
426424 }
427425
@@ -476,14 +474,14 @@ describe('stripIgnoredCharacters', () => {
476474 const strippedStr = stripIgnoredCharacters ( testStr ) ;
477475 const strippedValue = lexValue ( strippedStr ) ;
478476
479- /* istanbul ignore if */
480- if ( testValue !== strippedValue ) {
481- throw new Error ( dedent `
477+ invariant (
478+ testValue === strippedValue ,
479+ dedent `
482480 Expected lextOne(stripIgnoredCharacters(${ inspectStr ( testStr ) } ))
483481 to equal ${ inspectStr ( testValue ) }
484482 but got ${ inspectStr ( strippedValue ) }
485- ` ) ;
486- }
483+ ` ,
484+ ) ;
487485 }
488486 }
489487 } ) ;
0 commit comments