Skip to content

Commit

Permalink
Test reply function returning array with body object (#2219)
Browse files Browse the repository at this point in the history
Ref #2218
  • Loading branch information
paulmelnikow committed Jul 24, 2021
1 parent d3652a5 commit 7cab6b5
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/test_reply_function_sync.js
Expand Up @@ -319,6 +319,38 @@ describe('synchronous `reply()` function', () => {
scope.done()
})

it('handles status code, object body, and headers object', async () => {
const exampleBody = { foo: 'bar' }
const scope = nock('http://example.test')
.get('/')
.reply(() => [
202,
exampleBody,
{ 'x-key': 'value', 'x-key-2': 'value 2' },
])

const { statusCode, body, headers, rawHeaders } = await got(
'http://example.test/'
)

expect(statusCode).to.equal(202)
expect(body).to.equal(JSON.stringify(exampleBody))
expect(headers).to.deep.equal({
'content-type': 'application/json',
'x-key': 'value',
'x-key-2': 'value 2',
})
expect(rawHeaders).to.deep.equal([
'x-key',
'value',
'x-key-2',
'value 2',
'Content-Type',
'application/json',
])
scope.done()
})

it('when given a non-array, raises the expected error', async () => {
nock('http://example.test')
.get('/abc')
Expand Down

0 comments on commit 7cab6b5

Please sign in to comment.