Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test reply function returning array with body object #2219

Merged
merged 2 commits into from Jul 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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