-
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
e666f69
commit b17fd71
Showing
3 changed files
with
72 additions
and
17 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
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
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,38 @@ | ||
import { GraphQLClient } from '../src' | ||
import { setupTestServer } from './__helpers' | ||
|
||
const ctx = setupTestServer() | ||
|
||
describe('using class', () => { | ||
test('.setHeader() sets a header that get sent to server', async () => { | ||
const client = new GraphQLClient(ctx.url) | ||
client.setHeader('x-foo', 'bar') | ||
const mock = ctx.res() | ||
await client.request(`{ me { id } }`) | ||
expect(mock.requests[0].headers['x-foo']).toEqual('bar') | ||
}) | ||
|
||
describe('.setHeaders() sets headers that get sent to the server', () => { | ||
test('with headers instance', async () => { | ||
const client = new GraphQLClient(ctx.url) | ||
client.setHeaders(new Headers({ 'x-foo': 'bar' })) | ||
const mock = ctx.res() | ||
await client.request(`{ me { id } }`) | ||
expect(mock.requests[0].headers['x-foo']).toEqual('bar') | ||
}) | ||
test('with headers object', async () => { | ||
const client = new GraphQLClient(ctx.url) | ||
client.setHeaders({ 'x-foo': 'bar' }) | ||
const mock = ctx.res() | ||
await client.request(`{ me { id } }`) | ||
expect(mock.requests[0].headers['x-foo']).toEqual('bar') | ||
}) | ||
test('with header tuples', async () => { | ||
const client = new GraphQLClient(ctx.url) | ||
client.setHeaders([['x-foo', 'bar']]) | ||
const mock = ctx.res() | ||
await client.request(`{ me { id } }`) | ||
expect(mock.requests[0].headers['x-foo']).toEqual('bar') | ||
}) | ||
}) | ||
}) |