From 9688e4a54864ab7934ae47aabab48782169db9ee Mon Sep 17 00:00:00 2001 From: Alex LaFroscia Date: Fri, 6 Jul 2018 18:17:31 -0700 Subject: [PATCH 1/3] chore: remove Bower configuration file --- .bowerrc | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 .bowerrc 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 -} From eb6bfdffe01c0988d102e21395d549ab8f7d58ec Mon Sep 17 00:00:00 2001 From: Alex LaFroscia Date: Fri, 6 Jul 2018 19:47:50 -0700 Subject: [PATCH 2/3] chore(test): add test around not swallowing errors I was unable to actually re-create the scenario in the issue, but wrote this test around surfacing the error along the way so I decided to add it anyway. Related to #296 --- tests/unit/.gitkeep | 0 tests/unit/mixins/ajax-request-test.js | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+) delete mode 100644 tests/unit/.gitkeep 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..88b7628f 100644 --- a/tests/unit/mixins/ajax-request-test.js +++ b/tests/unit/mixins/ajax-request-test.js @@ -980,6 +980,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( From 6a5fa337b1a26737fb487f2a60e08de39cbaad81 Mon Sep 17 00:00:00 2001 From: Alex LaFroscia Date: Fri, 6 Jul 2018 20:18:42 -0700 Subject: [PATCH 3/3] fix: add test case around empty response 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 --- tests/unit/mixins/ajax-request-test.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/unit/mixins/ajax-request-test.js b/tests/unit/mixins/ajax-request-test.js index 88b7628f..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() {