Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
fix: add test case around empty response
Browse files Browse the repository at this point in the history
This was actually just about configuring jQuery correctly to prevent
parsing the response as JSON. Setting the `dataType` to `text` does this
correctly.

Closes #315
  • Loading branch information
alexlafroscia committed Jul 7, 2018
1 parent eb6bfdf commit 6a5fa33
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/unit/mixins/ajax-request-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from 'ember-ajax/errors';
import Pretender from 'pretender';
import { jsonResponse, jsonFactory } from 'dummy/tests/helpers/json';
import AjaxService from 'dummy/services/ajax';

const {
matchers: { anything, contains: matchContains }
Expand Down Expand Up @@ -790,6 +791,20 @@ describe('Unit | Mixin | ajax request', function() {
});
});

it('can handle an empty response', async function() {
this.server.post('/posts', () => [201, {}, undefined]);

const service = new AjaxService();

// NOTE: `dataType` must be set to `text`, otherwise jQuery will attempt
// to convert the response to JSON automatically
const response = await service.post('/posts', {
dataType: 'text'
});

expect(response).to.equal('');
});

describe('URL building', function() {
class NamespaceLeadingSlash extends AjaxRequest {
static get slashType() {
Expand Down

0 comments on commit 6a5fa33

Please sign in to comment.