Skip to content

Commit ce03161

Browse files
committed
Remove 'invariant' calls from 'stripIgnoredCharacters' tests
1 parent 91a4be2 commit ce03161

File tree

1 file changed

+41
-18
lines changed

1 file changed

+41
-18
lines changed

src/utilities/__tests__/stripIgnoredCharacters-test.js

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { expect } from 'chai';
44
import { describe, it } from 'mocha';
55

66
import dedent from '../../jsutils/dedent';
7-
import invariant from '../../jsutils/invariant';
87

98
import { parse } from '../../language/parser';
109
import { Source } from '../../language/source';
@@ -61,37 +60,47 @@ const nonPunctuatorTokens = [
6160
function lexValue(str) {
6261
const lexer = createLexer(new Source(str));
6362
const value = lexer.advance().value;
64-
invariant(lexer.advance().kind === '<EOF>');
63+
64+
/* istanbul ignore if */
65+
if (lexer.advance().kind !== '<EOF>') {
66+
throw new Error('Expected EOF');
67+
}
6568
return value;
6669
}
6770

6871
function expectStripped(docString) {
6972
return {
7073
toEqual(expected) {
7174
const stripped = stripIgnoredCharacters(docString);
72-
invariant(
73-
stripped === expected,
74-
`Expected stripIgnoredCharacters(${inspectStr(docString)})\n` +
75-
`\tto equal ${inspectStr(expected)}\n` +
76-
`\tbut got ${inspectStr(stripped)}`,
77-
);
75+
76+
/* istanbul ignore if */
77+
if (stripped !== expected) {
78+
throw new Error(dedent`
79+
Expected stripIgnoredCharacters(${inspectStr(docString)})
80+
to equal ${inspectStr(expected)}
81+
but got ${inspectStr(stripped)}
82+
`);
83+
}
7884

7985
const strippedTwice = stripIgnoredCharacters(stripped);
80-
invariant(
81-
stripped === strippedTwice,
82-
`Expected stripIgnoredCharacters(${inspectStr(stripped)})\n` +
83-
`\tto equal ${inspectStr(stripped)}\n` +
84-
`\tbut got ${inspectStr(strippedTwice)}`,
85-
);
86+
87+
/* istanbul ignore if */
88+
if (stripped !== strippedTwice) {
89+
throw new Error(dedent`
90+
Expected stripIgnoredCharacters(${inspectStr(stripped)})
91+
to equal ${inspectStr(stripped)}
92+
but got ${inspectStr(strippedTwice)}
93+
`);
94+
}
8695
},
8796
toStayTheSame() {
8897
this.toEqual(docString);
8998
},
9099
};
91100

101+
// Called only to make error messages for failing tests
102+
/* istanbul ignore next */
92103
function inspectStr(str) {
93-
// Called only to make error messages for failing tests
94-
/* istanbul ignore next */
95104
return JSON.stringify(str)
96105
.replace(/^"|"$/g, '`')
97106
.replace(/\\"/g, '"');
@@ -405,7 +414,14 @@ describe('stripIgnoredCharacters', () => {
405414
const strippedStr = stripIgnoredCharacters(blockStr);
406415
const strippedValue = lexValue(strippedStr);
407416

408-
invariant(originalValue === strippedValue);
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+
}
409425
return expectStripped(blockStr);
410426
}
411427

@@ -460,7 +476,14 @@ describe('stripIgnoredCharacters', () => {
460476
const strippedStr = stripIgnoredCharacters(testStr);
461477
const strippedValue = lexValue(strippedStr);
462478

463-
invariant(testValue === strippedValue);
479+
/* istanbul ignore if */
480+
if (testValue !== strippedValue) {
481+
throw new Error(dedent`
482+
Expected lextOne(stripIgnoredCharacters(${inspectStr(testStr)}))
483+
to equal ${inspectStr(testValue)}
484+
but got ${inspectStr(strippedValue)}
485+
`);
486+
}
464487
}
465488
}
466489
});

0 commit comments

Comments
 (0)