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

add testcases for nested list coercion #1528

Merged
merged 3 commits into from
Sep 27, 2018
Merged
Changes from 1 commit
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
36 changes: 36 additions & 0 deletions src/utilities/__tests__/coerceValue-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
GraphQLID,
GraphQLInt,
GraphQLFloat,
GraphQLList,
GraphQLString,
GraphQLEnumType,
GraphQLInputObjectType,
Expand Down Expand Up @@ -283,4 +284,39 @@ describe('coerceValue', () => {
]);
});
});

describe('for nested GraphQLList', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jjergus Thanks for PR 👍
I think it better to have describe for for GraphQLList and just implement all test from this table: http://facebook.github.io/graphql/June2018/#sec-Type-System.List

const TestList = GraphQLList(GraphQLList(GraphQLInt));

it('correctly coerces a nested list value', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to use existing naming convention, e.g.

it('returns value for integer', () => {
const result = coerceValue(1, GraphQLFloat);
expectValue(result).to.equal(1);
});

it('returns null for null value', () => {
const result = coerceValue(null, GraphQLInt);
expectValue(result).to.equal(null);
});

So instead of correctly coerces a nested list value it could be return value for nested list.
Same goes for other testcases

expectValue(coerceValue([[1], [2, 3]], TestList)).to.deep.equal([
[1],
[2, 3],
]);
});

it('correctly coerces a null value', () => {
expectValue(coerceValue(null, TestList)).to.deep.equal(null);
});

it('correctly coerces a non-list value', () => {
expectValue(coerceValue(42, TestList)).to.deep.equal([[42]]);
});

it('correctly coerces nested non-list values', () => {
expectValue(coerceValue([1, 2, 3], TestList)).to.deep.equal([
[1],
[2],
[3],
]);
});

it('correctly coerces nested null values', () => {
expectValue(coerceValue([42, [null], null], TestList)).to.deep.equal([
[42],
[null],
null,
]);
});
});
});