Skip to content

Commit

Permalink
Move isInputType & isOutputType test to rest of predicates test (#1661)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Jan 13, 2019
1 parent 4cdc8e2 commit d48e481
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 63 deletions.
34 changes: 1 addition & 33 deletions src/type/__tests__/definition-test.js
Expand Up @@ -27,7 +27,7 @@ import { describe, it } from 'mocha';
import { expect } from 'chai';

import inspect from '../../jsutils/inspect';
import { isObjectType, isInputType, isOutputType } from '../definition';
import { isObjectType } from '../definition';

const BlogImage = new GraphQLObjectType({
name: 'Image',
Expand Down Expand Up @@ -384,38 +384,6 @@ describe('Type System: Example', () => {
);
});

it('identifies input types', () => {
const expected = [
[GraphQLInt, true],
[ObjectType, false],
[InterfaceType, false],
[UnionType, false],
[EnumType, true],
[InputObjectType, true],
];
for (const [type, answer] of expected) {
expect(isInputType(type)).to.equal(answer);
expect(isInputType(GraphQLList(type))).to.equal(answer);
expect(isInputType(GraphQLNonNull(type))).to.equal(answer);
}
});

it('identifies output types', () => {
const expected = [
[GraphQLInt, true],
[ObjectType, true],
[InterfaceType, true],
[UnionType, true],
[EnumType, true],
[InputObjectType, false],
];
for (const [type, answer] of expected) {
expect(isOutputType(type)).to.equal(answer);
expect(isOutputType(GraphQLList(type))).to.equal(answer);
expect(isOutputType(GraphQLNonNull(type))).to.equal(answer);
}
});

it('prohibits nesting NonNull inside NonNull', () => {
// $DisableFlowOnNegativeTest
expect(() => GraphQLNonNull(GraphQLNonNull(GraphQLInt))).to.throw(
Expand Down
89 changes: 59 additions & 30 deletions src/type/__tests__/predicate-test.js
Expand Up @@ -255,60 +255,89 @@ describe('Type predicates', () => {
});

describe('isInputType', () => {
function expectInputType(type) {
expect(isInputType(type)).to.equal(true);
expect(() => assertInputType(type)).not.to.throw();
}

it('returns true for an input type', () => {
expect(isInputType(InputObjectType)).to.equal(true);
expect(() => assertInputType(InputObjectType)).not.to.throw();
expectInputType(GraphQLString);
expectInputType(EnumType);
expectInputType(InputObjectType);
});

it('returns true for a wrapped input type', () => {
expect(isInputType(GraphQLList(InputObjectType))).to.equal(true);
expect(() =>
assertInputType(GraphQLList(InputObjectType)),
).not.to.throw();
expect(isInputType(GraphQLNonNull(InputObjectType))).to.equal(true);
expect(() =>
assertInputType(GraphQLNonNull(InputObjectType)),
).not.to.throw();
expectInputType(GraphQLList(GraphQLString));
expectInputType(GraphQLList(EnumType));
expectInputType(GraphQLList(InputObjectType));

expectInputType(GraphQLNonNull(GraphQLString));
expectInputType(GraphQLNonNull(EnumType));
expectInputType(GraphQLNonNull(InputObjectType));
});

function expectNonInputType(type) {
expect(isInputType(type)).to.equal(false);
expect(() => assertInputType(type)).to.throw();
}

it('returns false for an output type', () => {
expect(isInputType(ObjectType)).to.equal(false);
expect(() => assertInputType(ObjectType)).to.throw();
expectNonInputType(ObjectType);
expectNonInputType(InterfaceType);
expectNonInputType(UnionType);
});

it('returns false for a wrapped output type', () => {
expect(isInputType(GraphQLList(ObjectType))).to.equal(false);
expect(() => assertInputType(GraphQLList(ObjectType))).to.throw();
expect(isInputType(GraphQLNonNull(ObjectType))).to.equal(false);
expect(() => assertInputType(GraphQLNonNull(ObjectType))).to.throw();
expectNonInputType(GraphQLList(ObjectType));
expectNonInputType(GraphQLList(InterfaceType));
expectNonInputType(GraphQLList(UnionType));

expectNonInputType(GraphQLNonNull(ObjectType));
expectNonInputType(GraphQLNonNull(InterfaceType));
expectNonInputType(GraphQLNonNull(UnionType));
});
});

describe('isOutputType', () => {
function expectOutputType(type) {
expect(isOutputType(type)).to.equal(true);
expect(() => assertOutputType(type)).not.to.throw();
}

it('returns true for an output type', () => {
expect(isOutputType(ObjectType)).to.equal(true);
expect(() => assertOutputType(ObjectType)).not.to.throw();
expectOutputType(GraphQLString);
expectOutputType(ObjectType);
expectOutputType(InterfaceType);
expectOutputType(UnionType);
expectOutputType(EnumType);
});

it('returns true for a wrapped output type', () => {
expect(isOutputType(GraphQLList(ObjectType))).to.equal(true);
expect(() => assertOutputType(GraphQLList(ObjectType))).not.to.throw();
expect(isOutputType(GraphQLNonNull(ObjectType))).to.equal(true);
expect(() => assertOutputType(GraphQLNonNull(ObjectType))).not.to.throw();
expectOutputType(GraphQLList(GraphQLString));
expectOutputType(GraphQLList(ObjectType));
expectOutputType(GraphQLList(InterfaceType));
expectOutputType(GraphQLList(UnionType));
expectOutputType(GraphQLList(EnumType));

expectOutputType(GraphQLNonNull(GraphQLString));
expectOutputType(GraphQLNonNull(ObjectType));
expectOutputType(GraphQLNonNull(InterfaceType));
expectOutputType(GraphQLNonNull(UnionType));
expectOutputType(GraphQLNonNull(EnumType));
});

function expectNonOutputType(type) {
expect(isOutputType(type)).to.equal(false);
expect(() => assertOutputType(type)).to.throw();
}

it('returns false for an input type', () => {
expect(isOutputType(InputObjectType)).to.equal(false);
expect(() => assertOutputType(InputObjectType)).to.throw();
expectNonOutputType(InputObjectType);
});

it('returns false for a wrapped input type', () => {
expect(isOutputType(GraphQLList(InputObjectType))).to.equal(false);
expect(() => assertOutputType(GraphQLList(InputObjectType))).to.throw();
expect(isOutputType(GraphQLNonNull(InputObjectType))).to.equal(false);
expect(() =>
assertOutputType(GraphQLNonNull(InputObjectType)),
).to.throw();
expectNonOutputType(GraphQLList(InputObjectType));
expectNonOutputType(GraphQLNonNull(InputObjectType));
});
});

Expand Down

0 comments on commit d48e481

Please sign in to comment.