diff --git a/tests/httpBlock.test.ts b/tests/httpBlock.test.ts index 4a9c58b..ed381ff 100644 --- a/tests/httpBlock.test.ts +++ b/tests/httpBlock.test.ts @@ -987,6 +987,45 @@ describe('http', < expect(result.result).toEqual(RESPONSE); }); + it('application/json serialization', async() => { + const path = getPath(); + + const RESPONSE = { + text: 'Привет!', + }; + fake.add(path, (req: ClientRequest, res: ServerResponse) => { + const buffer = Buffer.from(JSON.stringify(RESPONSE)); + res.setHeader('content-length', Buffer.byteLength(buffer)); + res.setHeader('content-type', 'application/json; charset=utf-8'); + res.end(buffer); + }); + + const block = baseBlock({ + block: { + pathname: path, + }, + options: { + after: ({ result }: { result: DescriptHttpBlockResult }) => JSON.stringify(result), + }, + }); + + const result = await de.run(block); + + expect(JSON.parse(result)).toEqual({ + headers: { + connection: 'keep-alive', + 'content-length': '24', + 'content-type': 'application/json; charset=utf-8', + date: expect.stringMatching(/^.* GMT$/), + 'keep-alive': 'timeout=5', + }, + result: { + text: 'Привет!', + }, + statusCode: 200, + }); + }); + it('text/plain, is_json: true', async() => { const path = getPath();