-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f1b7b5
commit fff4731
Showing
1 changed file
with
19 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 })) | ||
}) |