|
|
|
@ -135,7 +135,12 @@ describe('parseCredentials', () => { |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
describe('parseResponseBody', () => { |
|
|
|
|
const rsp = {} as unknown as Response; |
|
|
|
|
let rsp: Response; |
|
|
|
|
|
|
|
|
|
beforeEach(() => { |
|
|
|
|
rsp = new Response(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('parses json', async () => { |
|
|
|
|
const value = { hello: 'world' }; |
|
|
|
|
const body = await parseResponseBody( |
|
|
|
@ -148,6 +153,24 @@ describe('parseResponseBody', () => { |
|
|
|
|
expect(body).toEqual(value); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('returns an empty object {} when the response is empty but is declared as JSON type', async () => { |
|
|
|
|
rsp.headers.set('Content-Length', '0'); |
|
|
|
|
jest.spyOn(console, 'warn').mockImplementation(); |
|
|
|
|
|
|
|
|
|
const json = jest.fn(); |
|
|
|
|
const body = await parseResponseBody( |
|
|
|
|
{ |
|
|
|
|
...rsp, |
|
|
|
|
json, |
|
|
|
|
}, |
|
|
|
|
'json' |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
expect(body).toEqual({}); |
|
|
|
|
expect(json).not.toHaveBeenCalled(); |
|
|
|
|
expect(console.warn).toHaveBeenCalledTimes(1); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('parses text', async () => { |
|
|
|
|
const value = 'RAW TEXT'; |
|
|
|
|
const body = await parseResponseBody( |
|
|
|
|