From 2616dc797a8aed516bd51a746dbe015d66160e75 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Mon, 29 Mar 2021 15:52:16 +0300 Subject: [PATCH] tests: replace 'invariant' with 'expect' assertion whenever possible (#2999) --- src/execution/__tests__/union-interface-test.js | 4 +--- src/execution/__tests__/variables-test.js | 4 ++-- src/jsutils/__tests__/inspect-test.js | 5 ++--- src/language/__tests__/visitor-test.js | 4 +--- src/type/__tests__/introspection-test.js | 6 ++---- 5 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/execution/__tests__/union-interface-test.js b/src/execution/__tests__/union-interface-test.js index b887b7a220..6e8d1f98b1 100644 --- a/src/execution/__tests__/union-interface-test.js +++ b/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'; @@ -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'); }, }); diff --git a/src/execution/__tests__/variables-test.js b/src/execution/__tests__/variables-test.js index c4f968c622..1c45e2bc9d 100644 --- a/src/execution/__tests__/variables-test.js +++ b/src/execution/__tests__/variables-test.js @@ -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'; }, }); diff --git a/src/jsutils/__tests__/inspect-test.js b/src/jsutils/__tests__/inspect-test.js index 26da61e180..c600d2e435 100644 --- a/src/jsutils/__tests__/inspect-test.js +++ b/src/jsutils/__tests__/inspect-test.js @@ -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', () => { @@ -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]'); }); diff --git a/src/language/__tests__/visitor-test.js b/src/language/__tests__/visitor-test.js index bfe01c7719..6dda355cc5 100644 --- a/src/language/__tests__/visitor-test.js +++ b/src/language/__tests__/visitor-test.js @@ -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'; @@ -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'); }, }, { diff --git a/src/type/__tests__/introspection-test.js b/src/type/__tests__/introspection-test.js index 8ac12504b3..2e5f261e94 100644 --- a/src/type/__tests__/introspection-test.js +++ b/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'; @@ -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({