Skip to content

Commit d48e481

Browse files
Move isInputType & isOutputType test to rest of predicates test (#1661)
1 parent 4cdc8e2 commit d48e481

File tree

2 files changed

+60
-63
lines changed

2 files changed

+60
-63
lines changed

src/type/__tests__/definition-test.js

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { describe, it } from 'mocha';
2727
import { expect } from 'chai';
2828

2929
import inspect from '../../jsutils/inspect';
30-
import { isObjectType, isInputType, isOutputType } from '../definition';
30+
import { isObjectType } from '../definition';
3131

3232
const BlogImage = new GraphQLObjectType({
3333
name: 'Image',
@@ -384,38 +384,6 @@ describe('Type System: Example', () => {
384384
);
385385
});
386386

387-
it('identifies input types', () => {
388-
const expected = [
389-
[GraphQLInt, true],
390-
[ObjectType, false],
391-
[InterfaceType, false],
392-
[UnionType, false],
393-
[EnumType, true],
394-
[InputObjectType, true],
395-
];
396-
for (const [type, answer] of expected) {
397-
expect(isInputType(type)).to.equal(answer);
398-
expect(isInputType(GraphQLList(type))).to.equal(answer);
399-
expect(isInputType(GraphQLNonNull(type))).to.equal(answer);
400-
}
401-
});
402-
403-
it('identifies output types', () => {
404-
const expected = [
405-
[GraphQLInt, true],
406-
[ObjectType, true],
407-
[InterfaceType, true],
408-
[UnionType, true],
409-
[EnumType, true],
410-
[InputObjectType, false],
411-
];
412-
for (const [type, answer] of expected) {
413-
expect(isOutputType(type)).to.equal(answer);
414-
expect(isOutputType(GraphQLList(type))).to.equal(answer);
415-
expect(isOutputType(GraphQLNonNull(type))).to.equal(answer);
416-
}
417-
});
418-
419387
it('prohibits nesting NonNull inside NonNull', () => {
420388
// $DisableFlowOnNegativeTest
421389
expect(() => GraphQLNonNull(GraphQLNonNull(GraphQLInt))).to.throw(

src/type/__tests__/predicate-test.js

Lines changed: 59 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -255,60 +255,89 @@ describe('Type predicates', () => {
255255
});
256256

257257
describe('isInputType', () => {
258+
function expectInputType(type) {
259+
expect(isInputType(type)).to.equal(true);
260+
expect(() => assertInputType(type)).not.to.throw();
261+
}
262+
258263
it('returns true for an input type', () => {
259-
expect(isInputType(InputObjectType)).to.equal(true);
260-
expect(() => assertInputType(InputObjectType)).not.to.throw();
264+
expectInputType(GraphQLString);
265+
expectInputType(EnumType);
266+
expectInputType(InputObjectType);
261267
});
262268

263269
it('returns true for a wrapped input type', () => {
264-
expect(isInputType(GraphQLList(InputObjectType))).to.equal(true);
265-
expect(() =>
266-
assertInputType(GraphQLList(InputObjectType)),
267-
).not.to.throw();
268-
expect(isInputType(GraphQLNonNull(InputObjectType))).to.equal(true);
269-
expect(() =>
270-
assertInputType(GraphQLNonNull(InputObjectType)),
271-
).not.to.throw();
270+
expectInputType(GraphQLList(GraphQLString));
271+
expectInputType(GraphQLList(EnumType));
272+
expectInputType(GraphQLList(InputObjectType));
273+
274+
expectInputType(GraphQLNonNull(GraphQLString));
275+
expectInputType(GraphQLNonNull(EnumType));
276+
expectInputType(GraphQLNonNull(InputObjectType));
272277
});
273278

279+
function expectNonInputType(type) {
280+
expect(isInputType(type)).to.equal(false);
281+
expect(() => assertInputType(type)).to.throw();
282+
}
283+
274284
it('returns false for an output type', () => {
275-
expect(isInputType(ObjectType)).to.equal(false);
276-
expect(() => assertInputType(ObjectType)).to.throw();
285+
expectNonInputType(ObjectType);
286+
expectNonInputType(InterfaceType);
287+
expectNonInputType(UnionType);
277288
});
278289

279290
it('returns false for a wrapped output type', () => {
280-
expect(isInputType(GraphQLList(ObjectType))).to.equal(false);
281-
expect(() => assertInputType(GraphQLList(ObjectType))).to.throw();
282-
expect(isInputType(GraphQLNonNull(ObjectType))).to.equal(false);
283-
expect(() => assertInputType(GraphQLNonNull(ObjectType))).to.throw();
291+
expectNonInputType(GraphQLList(ObjectType));
292+
expectNonInputType(GraphQLList(InterfaceType));
293+
expectNonInputType(GraphQLList(UnionType));
294+
295+
expectNonInputType(GraphQLNonNull(ObjectType));
296+
expectNonInputType(GraphQLNonNull(InterfaceType));
297+
expectNonInputType(GraphQLNonNull(UnionType));
284298
});
285299
});
286300

287301
describe('isOutputType', () => {
302+
function expectOutputType(type) {
303+
expect(isOutputType(type)).to.equal(true);
304+
expect(() => assertOutputType(type)).not.to.throw();
305+
}
306+
288307
it('returns true for an output type', () => {
289-
expect(isOutputType(ObjectType)).to.equal(true);
290-
expect(() => assertOutputType(ObjectType)).not.to.throw();
308+
expectOutputType(GraphQLString);
309+
expectOutputType(ObjectType);
310+
expectOutputType(InterfaceType);
311+
expectOutputType(UnionType);
312+
expectOutputType(EnumType);
291313
});
292314

293315
it('returns true for a wrapped output type', () => {
294-
expect(isOutputType(GraphQLList(ObjectType))).to.equal(true);
295-
expect(() => assertOutputType(GraphQLList(ObjectType))).not.to.throw();
296-
expect(isOutputType(GraphQLNonNull(ObjectType))).to.equal(true);
297-
expect(() => assertOutputType(GraphQLNonNull(ObjectType))).not.to.throw();
316+
expectOutputType(GraphQLList(GraphQLString));
317+
expectOutputType(GraphQLList(ObjectType));
318+
expectOutputType(GraphQLList(InterfaceType));
319+
expectOutputType(GraphQLList(UnionType));
320+
expectOutputType(GraphQLList(EnumType));
321+
322+
expectOutputType(GraphQLNonNull(GraphQLString));
323+
expectOutputType(GraphQLNonNull(ObjectType));
324+
expectOutputType(GraphQLNonNull(InterfaceType));
325+
expectOutputType(GraphQLNonNull(UnionType));
326+
expectOutputType(GraphQLNonNull(EnumType));
298327
});
299328

329+
function expectNonOutputType(type) {
330+
expect(isOutputType(type)).to.equal(false);
331+
expect(() => assertOutputType(type)).to.throw();
332+
}
333+
300334
it('returns false for an input type', () => {
301-
expect(isOutputType(InputObjectType)).to.equal(false);
302-
expect(() => assertOutputType(InputObjectType)).to.throw();
335+
expectNonOutputType(InputObjectType);
303336
});
304337

305338
it('returns false for a wrapped input type', () => {
306-
expect(isOutputType(GraphQLList(InputObjectType))).to.equal(false);
307-
expect(() => assertOutputType(GraphQLList(InputObjectType))).to.throw();
308-
expect(isOutputType(GraphQLNonNull(InputObjectType))).to.equal(false);
309-
expect(() =>
310-
assertOutputType(GraphQLNonNull(InputObjectType)),
311-
).to.throw();
339+
expectNonOutputType(GraphQLList(InputObjectType));
340+
expectNonOutputType(GraphQLNonNull(InputObjectType));
312341
});
313342
});
314343

0 commit comments

Comments
 (0)