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

Close bug issues #363

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .bowerrc

This file was deleted.

Empty file removed tests/unit/.gitkeep
Empty file.
34 changes: 34 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 Expand Up @@ -980,6 +995,25 @@ describe('Unit | Mixin | ajax request', function() {
});
});

it('does not swallow errors from making the request', function() {
this.server.post('/posts', jsonFactory(200), 2);

class SomeThing {
toJSON() {
throw new Error('Some user error');
}
}

const service = new AjaxRequest();

expect(() => {
service.post('/posts', {
contentType: 'application/json',
data: new SomeThing()
});
}, 'Error was not swallowed').to.throw('Some user error');
});

function errorHandlerTest(status, errorClass) {
it(`handles a ${status} response correctly and preserves the payload`, function() {
this.server.get(
Expand Down