Skip to content

Commit

Permalink
tests: replace 'invariant' with 'expect' assertion whenever possible (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Mar 29, 2021
1 parent 33c069c commit 2616dc7
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 15 deletions.
4 changes: 1 addition & 3 deletions src/execution/__tests__/union-interface-test.js
@@ -1,8 +1,6 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';

import { invariant } from '../../jsutils/invariant';

import { parse } from '../../language/parser';

import { GraphQLSchema } from '../../type/schema';
Expand Down Expand Up @@ -123,7 +121,7 @@ const PetType = new GraphQLUnionType({
}

// istanbul ignore next (Not reachable. All possible types have been considered)
invariant(false);
expect.fail('Not reachable');
},
});

Expand Down
4 changes: 2 additions & 2 deletions src/execution/__tests__/variables-test.js
Expand Up @@ -25,11 +25,11 @@ import { getVariableValues } from '../values';
const TestComplexScalar = new GraphQLScalarType({
name: 'ComplexScalar',
parseValue(value) {
invariant(value === 'SerializedValue');
expect(value).to.equal('SerializedValue');
return 'DeserializedValue';
},
parseLiteral(ast) {
invariant(ast.value === 'SerializedValue');
expect(ast).to.include({ kind: 'StringValue', value: 'SerializedValue' });
return 'DeserializedValue';
},
});
Expand Down
5 changes: 2 additions & 3 deletions src/jsutils/__tests__/inspect-test.js
Expand Up @@ -2,7 +2,6 @@ import { expect } from 'chai';
import { describe, it } from 'mocha';

import { inspect } from '../inspect';
import { invariant } from '../invariant';

describe('inspect', () => {
it('undefined', () => {
Expand Down Expand Up @@ -35,13 +34,13 @@ describe('inspect', () => {
it('function', () => {
const unnamedFuncStr = inspect(
// istanbul ignore next (Never called and used as a placeholder)
() => invariant(false),
() => expect.fail('Should not be called'),
);
expect(unnamedFuncStr).to.equal('[function]');

// istanbul ignore next (Never called and used as a placeholder)
function namedFunc() {
invariant(false);
expect.fail('Should not be called');
}
expect(inspect(namedFunc)).to.equal('[function namedFunc]');
});
Expand Down
4 changes: 1 addition & 3 deletions src/language/__tests__/visitor-test.js
Expand Up @@ -3,8 +3,6 @@ import { describe, it } from 'mocha';

import { kitchenSinkQuery } from '../../__testUtils__/kitchenSinkQuery';

import { invariant } from '../../jsutils/invariant';

import type { ASTNode } from '../ast';
import { Kind } from '../kinds';
import { parse } from '../parser';
Expand Down Expand Up @@ -1076,7 +1074,7 @@ describe('Visitor', () => {
},
// istanbul ignore next (Never called and used as a placeholder)
leave() {
invariant(false);
expect.fail('Should not be called');
},
},
{
Expand Down
6 changes: 2 additions & 4 deletions src/type/__tests__/introspection-test.js
@@ -1,8 +1,6 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';

import { invariant } from '../../jsutils/invariant';

import { buildSchema } from '../../utilities/buildASTSchema';
import { getIntrospectionQuery } from '../../utilities/getIntrospectionQuery';

Expand Down Expand Up @@ -1569,12 +1567,12 @@ describe('Introspection', () => {

// istanbul ignore next (Called only to fail test)
function fieldResolver(_1, _2, _3, info) {
invariant(false, `Called on ${info.parentType.name}::${info.fieldName}`);
expect.fail(`Called on ${info.parentType.name}::${info.fieldName}`);
}

// istanbul ignore next (Called only to fail test)
function typeResolver(_1, _2, info) {
invariant(false, `Called on ${info.parentType.name}::${info.fieldName}`);
expect.fail(`Called on ${info.parentType.name}::${info.fieldName}`);
}

const result = graphqlSync({
Expand Down

0 comments on commit 2616dc7

Please sign in to comment.