diff --git a/.bowerrc b/.bowerrc deleted file mode 100644 index 959e1696..00000000 --- a/.bowerrc +++ /dev/null @@ -1,4 +0,0 @@ -{ - "directory": "bower_components", - "analytics": false -} diff --git a/tests/unit/.gitkeep b/tests/unit/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/unit/mixins/ajax-request-test.js b/tests/unit/mixins/ajax-request-test.js index 791a481f..f0662415 100644 --- a/tests/unit/mixins/ajax-request-test.js +++ b/tests/unit/mixins/ajax-request-test.js @@ -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 } @@ -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() { @@ -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(