-
-
Notifications
You must be signed in to change notification settings - Fork 517
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds GraphQL errors integration test
- Loading branch information
1 parent
4436075
commit 680c53a
Showing
2 changed files
with
77 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { composeMocks, graphql } from 'msw' | ||
|
||
const { start } = composeMocks( | ||
graphql.query({ operation: 'Login' }, (req, res, ctx) => { | ||
return res( | ||
ctx.errors([ | ||
{ | ||
message: 'This is a mocked error', | ||
locations: [ | ||
{ | ||
line: 1, | ||
column: 2, | ||
}, | ||
], | ||
}, | ||
]), | ||
) | ||
}), | ||
) | ||
|
||
start() |
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import * as path from 'path' | ||
import { Response } from 'puppeteer' | ||
import { TestAPI, runBrowserWith } from '../support/runBrowserWith' | ||
import { executeOperation } from './utils/executeOperation' | ||
|
||
describe('GraphQL: Errors', () => { | ||
let api: TestAPI | ||
|
||
beforeAll(async () => { | ||
api = await runBrowserWith(path.resolve(__dirname, 'errors.mocks.ts')) | ||
}) | ||
|
||
afterAll(() => { | ||
return api.cleanup() | ||
}) | ||
|
||
describe('given mocked query errors', () => { | ||
let res: Response | ||
let body: Record<string, any> | ||
|
||
beforeAll(async () => { | ||
res = await executeOperation(api.page, { | ||
query: ` | ||
query Login { | ||
user { | ||
id | ||
} | ||
} | ||
`, | ||
}) | ||
body = await res.json() | ||
}) | ||
|
||
it('should return 200 status code', () => { | ||
expect(res.status()).toBe(200) | ||
}) | ||
|
||
it('should not return any data', () => { | ||
expect(body).not.toHaveProperty('data') | ||
}) | ||
|
||
it('should mock the error', () => { | ||
expect(body).toHaveProperty('errors', [ | ||
{ | ||
message: 'This is a mocked error', | ||
locations: [ | ||
{ | ||
line: 1, | ||
column: 2, | ||
}, | ||
], | ||
}, | ||
]) | ||
}) | ||
}) | ||
}) |