ember-cli-mirage: v0.4.9: A previously working POST now fails with `Unexpected end of JSON input`

Hello and thank you for this great addon.

I am using Ember v3.3.1.

I have a test that passes with version 0.4.7 and 0.4.8 but fails with 0.4.9.

The test dies on a POST:

SyntaxError: Unexpected end of JSON input
    at parse (<anonymous>)
    at ajaxConvert (jquery.js:8787)
    at done (jquery.js:9255)
    at FakeRequest.<anonymous> (jquery.js:9548)
    at FakeRequest.<anonymous> (fake_xml_http_request.js:137)
    at FakeRequest.dispatchEvent (fake_xml_http_request.js:181)
    at FakeRequest._readyStateChange (fake_xml_http_request.js:389)
    at FakeRequest._setResponseBody (fake_xml_http_request.js:453)
    at FakeRequest.respond (fake_xml_http_request.js:474)
    at Object.callback (pretender.js:378)

This error is thrown when the hook saveof the model for which a POST is required is called. I have compared the two JSON of this test on the 2 versions of Mirage (0.4.8 and 0.4.9) and they are identical (and valid) which is not a surprise.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 27

Commits related to this issue

Most upvoted comments

@CygnusRoboticus You absolutely should not have to change that route handler as a result of a patch version, it was a bug introduced. I am going to fix this in another patch version.

@OpakAlex As I said I needed more help understanding what was broken. When we worked on this change I added tests covering what I thought was the current behavior, and everything passed after the change. Therefore the change is in fact a bug introduced rather than a deliberate change.

I should have some time to look at this soon. Thanks for the example!

@samselikoff I checked your changes, tests are green 👍

@samselikoff Sorry for lack of response back in Nov, I missed the notification somehow. I removed my manual return new Response(404, {}, {}) calls and my test suite is green on #1447. 👍

@mydea @OpakAlex @CygnusRoboticus @agneslovelace @stfnio 👋 I believe I have a better fix in place for this issue now.

Could I enlist some help from you all, and get you to install PR #1447 by adding this to your package.json

"ember-cli-mirage": "samselikoff/ember-cli-mirage#1370-falsy-responses-test"

running yarn or npm install and see if that fixes the tests you were having trouble with?

(I have a better understanding of previous change and I believe I’ve moved the fix to the right place, without requiring either a breaking change for existing behavior or anything new to accommodate the original problem raised in https://github.com/samselikoff/ember-cli-mirage/issues/1295).

I am going to revert this change , add a deprecation, and add back in the fix in 0.5. Will be getting to this soon.

It was not intended to be a breaking change, it’s sometimes hard to know a as a library author how undocumented behavior is relied upon by users. Sorry about the confusion this has caused!

No worries, glad you got it working! We did change the default content body for some requests so I wouldn’t be surprised if we see some other reports. I’ll keep my eye out.