it('leaves body as is if response header content type is not JSON', () => { const body = 'plain string'; const response = new Response( body, { status: 200 } ); GLOBAL.fetch = sinon.spy(() => Promise.resolve(response)); const client = new Client(); client.addPlugin(jsonPlugin); return client.post('endpoint').then(() => response.parsedBody().then(parsed => { expect(parsed).to.eql(body); })); });
it('JSON encodes response if response header content type starts with "application/json"', () => { const body = { content: 'here it is' }; const response = new Response( JSON.stringify(body), { status: 200, headers: { 'Content-Type': 'application/json; charset=utf-8', }, } ); GLOBAL.fetch = sinon.spy(() => Promise.resolve(response)); const client = new Client(); client.addPlugin(jsonPlugin); return client.post('endpoint').then(() => response.parsedBody().then(parsed => { expect(parsed).to.eql(body); })); });
return client.post('endpoint').then(() => response.parsedBody().then(parsed => { expect(parsed).to.eql(body); }));