Skip to content

Commit f474a4e

Browse files
Citomjmahone
authored andcommitted
Add unit tests for isRequired predicates (#1486)
1 parent 350a7d2 commit f474a4e

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

src/type/__tests__/predicate-test.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ import {
3535
isWrappingType,
3636
isNullableType,
3737
isNamedType,
38+
isRequiredArgument,
39+
isRequiredInputField,
3840
assertType,
3941
assertScalarType,
4042
assertObjectType,
@@ -469,4 +471,70 @@ describe('Type predicates', () => {
469471
).to.equal(ObjectType);
470472
});
471473
});
474+
475+
describe('isRequiredArgument', () => {
476+
it('returns true for required arguments', () => {
477+
const requiredArg = {
478+
type: GraphQLNonNull(GraphQLString),
479+
};
480+
expect(isRequiredArgument(requiredArg)).to.equal(true);
481+
});
482+
483+
it('returns false for optional arguments', () => {
484+
const optArg1 = {
485+
type: GraphQLString,
486+
};
487+
expect(isRequiredArgument(optArg1)).to.equal(false);
488+
489+
const optArg2 = {
490+
type: GraphQLString,
491+
defaultValue: null,
492+
};
493+
expect(isRequiredArgument(optArg2)).to.equal(false);
494+
495+
const optArg3 = {
496+
type: GraphQLList(GraphQLNonNull(GraphQLString)),
497+
};
498+
expect(isRequiredArgument(optArg3)).to.equal(false);
499+
500+
const optArg4 = {
501+
type: GraphQLNonNull(GraphQLString),
502+
defaultValue: 'default',
503+
};
504+
expect(isRequiredArgument(optArg4)).to.equal(false);
505+
});
506+
});
507+
508+
describe('isRequiredInputField', () => {
509+
it('returns true for required input field', () => {
510+
const requiredField = {
511+
type: GraphQLNonNull(GraphQLString),
512+
};
513+
expect(isRequiredInputField(requiredField)).to.equal(true);
514+
});
515+
516+
it('returns false for optional input field', () => {
517+
const optField1 = {
518+
type: GraphQLString,
519+
};
520+
expect(isRequiredInputField(optField1)).to.equal(false);
521+
522+
const optField2 = {
523+
type: GraphQLString,
524+
defaultValue: null,
525+
};
526+
expect(isRequiredInputField(optField2)).to.equal(false);
527+
528+
const optField3 = {
529+
type: GraphQLList(GraphQLNonNull(GraphQLString)),
530+
};
531+
expect(isRequiredInputField(optField3)).to.equal(false);
532+
533+
const optField4 = {
534+
type: GraphQLNonNull(GraphQLString),
535+
defaultValue: 'default',
536+
};
537+
expect(isRequiredInputField(optField4)).to.equal(false);
538+
});
539+
});
472540
});

0 commit comments

Comments
 (0)