Skip to content

Commit

Permalink
Improve test
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Jul 5, 2024
1 parent 431f1dd commit 431303f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/executors/http/tests/buildHTTPExecutor.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createServer, Server } from 'http';
import { GraphQLError, parse } from 'graphql';
import { createGraphQLError, ExecutionResult } from '@graphql-tools/utils';
import { createGraphQLError, ExecutionResult, isAsyncIterable } from '@graphql-tools/utils';
import { ReadableStream, Request, Response } from '@whatwg-node/fetch';
import { assertAsyncIterable } from '../../../loaders/url/tests/test-utils.js';
import { buildHTTPExecutor } from '../src/index.js';
Expand Down Expand Up @@ -259,19 +259,21 @@ describe('buildHTTPExecutor', () => {
const executor = buildHTTPExecutor({
useGETForQueries: true,
fetch() {
return new Response(JSON.stringify({ errors: [{ message: 'test error' }] }), {
headers: { 'Content-Type': 'application/json' },
});
return Response.json({ errors: [{ message: 'test error' }] });
},
});

const result = (await executor({
const result = await executor({
document: parse(/* GraphQL */ `
query {
hello
}
`),
})) as ExecutionResult;
});

if (isAsyncIterable(result)) {
throw new Error('Expected result to be an ExecutionResult');
}

expect(result.errors?.[0]).toBeInstanceOf(GraphQLError);
expect(result.errors?.[0]?.extensions).toMatchObject({
Expand Down

0 comments on commit 431303f

Please sign in to comment.