-
Notifications
You must be signed in to change notification settings - Fork 558
/
useGraphiQL.spec.ts
34 lines (32 loc) 路 1.09 KB
/
useGraphiQL.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { createYoga } from '../server'
describe('GraphiQL', () => {
describe('when received an option factory that returns Promise', () => {
it('should respect graphiql option', async () => {
const yoga = createYoga({
graphiql: () => Promise.resolve({ title: 'Test GraphiQL' }),
})
const response = await yoga.fetch('http://localhost:3000/graphql', {
method: 'GET',
headers: {
Accept: 'text/html',
},
})
expect(response.headers.get('content-type')).toEqual('text/html')
const result = await response.text()
expect(result).toMatch(/<title>Test GraphiQL<\/title>/)
})
it('returns error when graphiql is disabled', async () => {
const yoga = createYoga({
graphiql: () => Promise.resolve(false),
})
const response = await yoga.fetch('http://localhost:3000/graphql', {
method: 'GET',
headers: {
Accept: 'text/html',
},
})
expect(response.headers.get('content-type')).not.toEqual('text/html')
expect(response.status).toEqual(406)
})
})
})