@@ -4,6 +4,7 @@ import { expect } from 'chai';
4
4
import { describe , it } from 'mocha' ;
5
5
6
6
import dedent from '../../jsutils/dedent' ;
7
+ import invariant from '../../jsutils/invariant' ;
7
8
8
9
import { parse } from '../../language/parser' ;
9
10
import { Source } from '../../language/source' ;
@@ -61,10 +62,7 @@ function lexValue(str) {
61
62
const lexer = createLexer ( new Source ( str ) ) ;
62
63
const value = lexer . advance ( ) . value ;
63
64
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' ) ;
68
66
return value ;
69
67
}
70
68
@@ -81,25 +79,25 @@ function expectStripped(docString) {
81
79
toEqual ( expected ) {
82
80
const stripped = stripIgnoredCharacters ( docString ) ;
83
81
84
- /* istanbul ignore if */
85
- if ( stripped !== expected ) {
86
- throw new Error ( dedent `
82
+ invariant (
83
+ stripped === expected ,
84
+ dedent `
87
85
Expected stripIgnoredCharacters(${ inspectStr ( docString ) } )
88
86
to equal ${ inspectStr ( expected ) }
89
87
but got ${ inspectStr ( stripped ) }
90
- ` ) ;
91
- }
88
+ ` ,
89
+ ) ;
92
90
93
91
const strippedTwice = stripIgnoredCharacters ( stripped ) ;
94
92
95
- /* istanbul ignore if */
96
- if ( stripped !== strippedTwice ) {
97
- throw new Error ( dedent `
93
+ invariant (
94
+ stripped === strippedTwice ,
95
+ dedent `
98
96
Expected stripIgnoredCharacters(${ inspectStr ( stripped ) } )
99
97
to equal ${ inspectStr ( stripped ) }
100
98
but got ${ inspectStr ( strippedTwice ) }
101
- ` ) ;
102
- }
99
+ ` ,
100
+ ) ;
103
101
} ,
104
102
toStayTheSame ( ) {
105
103
this . toEqual ( docString ) ;
@@ -414,14 +412,14 @@ describe('stripIgnoredCharacters', () => {
414
412
const strippedStr = stripIgnoredCharacters ( blockStr ) ;
415
413
const strippedValue = lexValue ( strippedStr ) ;
416
414
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
+ ) ;
425
423
return expectStripped ( blockStr ) ;
426
424
}
427
425
@@ -476,14 +474,14 @@ describe('stripIgnoredCharacters', () => {
476
474
const strippedStr = stripIgnoredCharacters ( testStr ) ;
477
475
const strippedValue = lexValue ( strippedStr ) ;
478
476
479
- /* istanbul ignore if */
480
- if ( testValue !== strippedValue ) {
481
- throw new Error ( dedent `
477
+ invariant (
478
+ testValue === strippedValue ,
479
+ dedent `
482
480
Expected lextOne(stripIgnoredCharacters(${ inspectStr ( testStr ) } ))
483
481
to equal ${ inspectStr ( testValue ) }
484
482
but got ${ inspectStr ( strippedValue ) }
485
- ` ) ;
486
- }
483
+ ` ,
484
+ ) ;
487
485
}
488
486
}
489
487
} ) ;
0 commit comments