From 7cab6b582623b5c42d8f4acc2e891f78441e5c17 Mon Sep 17 00:00:00 2001 From: Paul Melnikow Date: Sat, 24 Jul 2021 10:22:56 -0500 Subject: [PATCH] Test reply function returning array with body object (#2219) Ref #2218 --- tests/test_reply_function_sync.js | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/test_reply_function_sync.js b/tests/test_reply_function_sync.js index 83ead902b..cf36b23cc 100644 --- a/tests/test_reply_function_sync.js +++ b/tests/test_reply_function_sync.js @@ -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')