Skip to content

Commit

Permalink
improve code coverage
Browse files Browse the repository at this point in the history
...now that subscribe and createSourceEventStream both call buildExecutionContext, build errors must be tested separately
  • Loading branch information
yaacovCR committed Jun 20, 2022
1 parent 31f3204 commit f2cacd4
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/execution/__tests__/subscribe-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { GraphQLList, GraphQLObjectType } from '../../type/definition';
import { GraphQLBoolean, GraphQLInt, GraphQLString } from '../../type/scalars';
import { GraphQLSchema } from '../../type/schema';

import type { ExecutionResult } from '../execute';
import type { ExecutionArgs, ExecutionResult } from '../execute';
import { createSourceEventStream, subscribe } from '../execute';

import { SimplePubSub } from './simplePubSub';
Expand Down Expand Up @@ -195,6 +195,15 @@ function subscribeWithBadFn(
);
}

function subscribeWithBadArgs(
args: ExecutionArgs,
): PromiseOrValue<ExecutionResult | AsyncIterable<unknown>> {
return expectEqualPromisesOrValues(
subscribe(args),
createSourceEventStream(args),
);
}

/* eslint-disable @typescript-eslint/require-await */
// Check all error cases when initializing the subscription.
describe('Subscription Initialization Phase', () => {
Expand Down Expand Up @@ -394,7 +403,7 @@ describe('Subscription Initialization Phase', () => {
const schema = new GraphQLSchema({ query: DummyQueryType });
const document = parse('subscription { unknownField }');

const result = subscribe({ schema, document });
const result = subscribeWithBadArgs({ schema, document });
expectJSON(result).toDeepEqual({
errors: [
{
Expand All @@ -418,7 +427,7 @@ describe('Subscription Initialization Phase', () => {
});
const document = parse('subscription { unknownField }');

const result = subscribe({ schema, document });
const result = subscribeWithBadArgs({ schema, document });
expectJSON(result).toDeepEqual({
errors: [
{
Expand All @@ -441,7 +450,7 @@ describe('Subscription Initialization Phase', () => {
});

// @ts-expect-error
expect(() => subscribe({ schema, document: {} })).to.throw();
expect(() => subscribeWithBadArgs({ schema, document: {} })).to.throw();
});

it('throws an error if subscribe does not return an iterator', async () => {
Expand Down Expand Up @@ -526,7 +535,7 @@ describe('Subscription Initialization Phase', () => {

// If we receive variables that cannot be coerced correctly, subscribe() will
// resolve to an ExecutionResult that contains an informative error description.
const result = subscribe({ schema, document, variableValues });
const result = subscribeWithBadArgs({ schema, document, variableValues });
expectJSON(result).toDeepEqual({
errors: [
{
Expand Down

0 comments on commit f2cacd4

Please sign in to comment.