diff --git a/tests/errorPolicy.test.ts b/tests/errorPolicy.test.ts index db1f13956..8fb1ed08d 100644 --- a/tests/errorPolicy.test.ts +++ b/tests/errorPolicy.test.ts @@ -1,63 +1,36 @@ import { GraphQLClient } from '../src/entrypoints/main.js' import { setupMockServer } from './__helpers.js' -import { expect, test } from 'vitest' +import { describe, expect, test } from 'vitest' const ctx = setupMockServer() const errors = { message: `Syntax Error GraphQL request (1:1) Unexpected Name "x"\n\n1: x\n ^\n`, - locations: [ - { - line: 1, - column: 1, - }, - ], + locations: [{ line: 1, column: 1 }], } -test(`should throw error when error policy not set`, async () => { - ctx.res({ - body: { - data: {}, - errors, - }, +describe(`should throw error`, () => { + test(`should throw error when error policy not set`, async () => { + ctx.res({ body: { data: {}, errors } }) + await expect(() => new GraphQLClient(ctx.url).rawRequest(`x`)).rejects.toThrow(`GraphQL Error`) }) - await expect(() => new GraphQLClient(ctx.url).rawRequest(`x`)).rejects.toThrow(`GraphQL Error`) -}) - -test(`should throw error when error policy set to "none"`, async () => { - ctx.res({ - body: { - data: {}, - errors, - }, + test(`when error policy set to "none"`, async () => { + ctx.res({ body: { data: {}, errors } }) + await expect(() => new GraphQLClient(ctx.url).rawRequest(`x`)).rejects.toThrow(`GraphQL Error`) }) - - await expect(() => new GraphQLClient(ctx.url).rawRequest(`x`)).rejects.toThrow(`GraphQL Error`) }) -test(`should not throw error when error policy set to "ignore" and return only data`, async () => { - ctx.res({ - body: { - data: { test: {} }, - errors, - }, +describe(`should not throw error`, () => { + test(`when error policy set to "ignore" and return only data`, async () => { + ctx.res({ body: { data: { test: {} }, errors } }) + const res = await new GraphQLClient(ctx.url, { errorPolicy: `ignore` }).rawRequest(`x`) + expect(res).toEqual(expect.objectContaining({ data: { test: {} } })) + expect(res).toEqual(expect.not.objectContaining({ errors })) }) - const res = await new GraphQLClient(ctx.url, { errorPolicy: `ignore` }).rawRequest(`x`) - - expect(res).toEqual(expect.objectContaining({ data: { test: {} } })) - expect(res).toEqual(expect.not.objectContaining({ errors })) -}) - -test(`should not throw error when error policy set to "all" and return both data and error`, async () => { - ctx.res({ - body: { - data: { test: {} }, - errors, - }, + test(`when error policy set to "all" and return both data and error`, async () => { + ctx.res({ body: { data: { test: {} }, errors } }) + const res = await new GraphQLClient(ctx.url, { errorPolicy: `all` }).rawRequest(`x`) + expect(res).toEqual(expect.objectContaining({ data: { test: {} }, errors })) }) - - const res = await new GraphQLClient(ctx.url, { errorPolicy: `all` }).rawRequest(`x`) - - expect(res).toEqual(expect.objectContaining({ data: { test: {} }, errors })) })