Skip to content

Commit 92ad909

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

File tree

1 file changed

+47
-24
lines changed

1 file changed

+47
-24
lines changed

src/utilities/__tests__/stripIgnoredCharacters-test.js

Lines changed: 47 additions & 24 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,41 +60,51 @@ 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

71+
// Called only to make error messages for failing tests
72+
/* istanbul ignore next */
73+
function inspectStr(str) {
74+
return (JSON.stringify(str) || '')
75+
.replace(/^"|"$/g, '`')
76+
.replace(/\\"/g, '"');
77+
}
78+
6879
function expectStripped(docString) {
6980
return {
7081
toEqual(expected) {
7182
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-
);
83+
84+
/* istanbul ignore if */
85+
if (stripped !== expected) {
86+
throw new Error(dedent`
87+
Expected stripIgnoredCharacters(${inspectStr(docString)})
88+
to equal ${inspectStr(expected)}
89+
but got ${inspectStr(stripped)}
90+
`);
91+
}
7892

7993
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-
);
94+
95+
/* istanbul ignore if */
96+
if (stripped !== strippedTwice) {
97+
throw new Error(dedent`
98+
Expected stripIgnoredCharacters(${inspectStr(stripped)})
99+
to equal ${inspectStr(stripped)}
100+
but got ${inspectStr(strippedTwice)}
101+
`);
102+
}
86103
},
87104
toStayTheSame() {
88105
this.toEqual(docString);
89106
},
90107
};
91-
92-
function inspectStr(str) {
93-
// Called only to make error messages for failing tests
94-
/* istanbul ignore next */
95-
return JSON.stringify(str)
96-
.replace(/^"|"$/g, '`')
97-
.replace(/\\"/g, '"');
98-
}
99108
}
100109

101110
describe('stripIgnoredCharacters', () => {
@@ -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)