Skip to content

Add unit tests for isRequired predicates #1486

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

Merged
merged 1 commit into from
Aug 28, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions src/type/__tests__/predicate-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import {
isWrappingType,
isNullableType,
isNamedType,
isRequiredArgument,
isRequiredInputField,
assertType,
assertScalarType,
assertObjectType,
Expand Down Expand Up @@ -469,4 +471,70 @@ describe('Type predicates', () => {
).to.equal(ObjectType);
});
});

describe('isRequiredArgument', () => {
it('returns true for required arguments', () => {
const requiredArg = {
type: GraphQLNonNull(GraphQLString),
};
expect(isRequiredArgument(requiredArg)).to.equal(true);
});

it('returns false for optional arguments', () => {
const optArg1 = {
type: GraphQLString,
};
expect(isRequiredArgument(optArg1)).to.equal(false);

const optArg2 = {
type: GraphQLString,
defaultValue: null,
};
expect(isRequiredArgument(optArg2)).to.equal(false);

const optArg3 = {
type: GraphQLList(GraphQLNonNull(GraphQLString)),
};
expect(isRequiredArgument(optArg3)).to.equal(false);

const optArg4 = {
type: GraphQLNonNull(GraphQLString),
defaultValue: 'default',
};
expect(isRequiredArgument(optArg4)).to.equal(false);
});
});

describe('isRequiredInputField', () => {
it('returns true for required input field', () => {
const requiredField = {
type: GraphQLNonNull(GraphQLString),
};
expect(isRequiredInputField(requiredField)).to.equal(true);
});

it('returns false for optional input field', () => {
const optField1 = {
type: GraphQLString,
};
expect(isRequiredInputField(optField1)).to.equal(false);

const optField2 = {
type: GraphQLString,
defaultValue: null,
};
expect(isRequiredInputField(optField2)).to.equal(false);

const optField3 = {
type: GraphQLList(GraphQLNonNull(GraphQLString)),
};
expect(isRequiredInputField(optField3)).to.equal(false);

const optField4 = {
type: GraphQLNonNull(GraphQLString),
defaultValue: 'default',
};
expect(isRequiredInputField(optField4)).to.equal(false);
});
});
});