Skip to content

Commit

Permalink
Add tests for supporting Iterable collections across the lib (graphql…
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov authored and yaacovCR committed Apr 11, 2021
1 parent fdddfb1 commit 98a4511
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/execution/__tests__/lists-test.js
Expand Up @@ -40,8 +40,8 @@ describe('Execute: Accepts any iterable as list value', () => {
});

it('Accepts function arguments as a List value', () => {
function getArgs(...args: Array<string>) {
return args;
function getArgs(..._args: Array<string>) {
return arguments;
}
const listField = getArgs('one', 'two');

Expand Down
17 changes: 17 additions & 0 deletions src/utilities/__tests__/astFromValue-test.js
Expand Up @@ -293,6 +293,23 @@ describe('astFromValue', () => {
{ kind: 'EnumValue', value: 'GOODBYE' },
],
});

function* listGenerator() {
yield 1;
yield 2;
yield 3;
}

expect(
astFromValue(listGenerator(), new GraphQLList(GraphQLInt)),
).to.deep.equal({
kind: 'ListValue',
values: [
{ kind: 'IntValue', value: '1' },
{ kind: 'IntValue', value: '2' },
{ kind: 'IntValue', value: '3' },
],
});
});

it('converts list singletons', () => {
Expand Down
11 changes: 11 additions & 0 deletions src/utilities/__tests__/coerceInputValue-test.js
Expand Up @@ -303,6 +303,17 @@ describe('coerceInputValue', () => {
expectValue(result).to.deep.equal([1, 2, 3]);
});

it('returns no error for a valid iterable input', () => {
function* listGenerator() {
yield 1;
yield 2;
yield 3;
}

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

it('returns an error for an invalid input', () => {
const result = coerceValue([1, 'b', true, 4], TestList);
expectErrors(result).to.deep.equal([
Expand Down

0 comments on commit 98a4511

Please sign in to comment.