ember-cli-mirage icon indicating copy to clipboard operation
ember-cli-mirage copied to clipboard

Mirage Passthrough returns Response Object instead of JSON data returned from network call

Open shreyashah7 opened this issue 5 years ago • 2 comments

I was getting an error: testem.js:1063 Mirage: Your Ember app tried to GET 'http://localhost:3006/asset-manifest.json', but there was no route defined to handle this request. Define a route that matches this path in your mirage/config.js file. Did you forget to add your namespace?

So following the documentation of mirage i added this: this.passthrough('http://localhost:3006/asset-manifest.json');

Even though after adding passthrough, I am getting Mirage Response instead of JSON Object returned from the network api call.

The response i am getting is:

{bodyUsed: true
headers: Headers {map: {…}}
ok: true
status: 200
statusText: "OK"
type: "default"
url: "http://localhost:3006/asset-manifest.json"
_bodyInit: null
_bodyText: ""}

But I am expecting:

{ "files": { "main.js": "/static/js/main.427b5b21.js", "index.html": "/index.html", "precache-manifest.f0c17b0567a3f91c46fb3e8e660eb34c.js": "/precache-manifest.f0c17b0567a3f91c46fb3e8e660eb34c.js", "service-worker.js": "/service-worker.js" } }

I kept a debugger in Pretender.js which is sending the FakeRequest and there in its object, I see that FakeRequest has responseType="" and response as null. And somehow my responseText has value but that is not considered and response value is considered and receiving null.

Also there is a logic which is return saying

"response" in xhr ? xhr.response : xhr.responseText

In this case i have response property but its value is null. Hence according to the above condition it is returning xhr.response which is null

Please Help.

shreyashah7 avatar Jul 31 '20 03:07 shreyashah7

I am getting the same error, call is getting executed and is visible under network tab. But in response, it just fulfills the promise but doesn't returns the actual response I'm getting from Api.

tushartiwari7 avatar Apr 25 '22 16:04 tushartiwari7

All this code has been extracted to MirageJS. This repo only supports importing MirageJS into ember and some test helpers.

Please open an issue in the MirageJS Issues. Hopefully someone there can help you and if there is a bug, its that repo that will provide the fix.

cah-brian-gantzler avatar Apr 25 '22 17:04 cah-brian-gantzler