Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: replace 'invariant' with 'expect' assertion whenever possible #2999

Merged
merged 1 commit into from Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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