@lion/ajax
Advanced tools
Comparing version 1.1.2 to 1.1.3
{ | ||
"name": "@lion/ajax", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "Thin wrapper around fetch with support for interceptors.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -196,3 +196,6 @@ /* eslint-disable consistent-return */ | ||
let body = responseText; | ||
if (response.headers.get('content-type')?.includes('json')) { | ||
if ( | ||
!response.headers.get('content-type') || | ||
response.headers.get('content-type')?.includes('json') | ||
) { | ||
try { | ||
@@ -199,0 +202,0 @@ body = JSON.parse(responseText); |
@@ -169,2 +169,19 @@ import { expect } from '@open-wc/testing'; | ||
it('tries to parse Response body as JSON if the content-type header is missing', async () => { | ||
fetchStub.restore(); | ||
fetchStub = stub(window, 'fetch'); | ||
fetchStub.callsFake(() => { | ||
const resp = new Response('{"a":1,"b":2}', { | ||
headers: { | ||
// eslint-disable-next-line no-plusplus | ||
'x-request-id': `${responseId++}`, | ||
}, | ||
}); | ||
resp.headers.delete('content-type'); | ||
return Promise.resolve(resp); | ||
}); | ||
const response = await ajax.fetchJson('/foo'); | ||
expect(response.body).to.eql({ a: 1, b: 2 }); | ||
}); | ||
describe('given a request body', () => { | ||
@@ -171,0 +188,0 @@ it('encodes the request body as json', async () => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
178900
3010