You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue
Seems like pretender's passthrough does not take into account the responseType value that was set in original XMLHttpRequest object.
The issue can be reproduced by the following snippet:
importPretenderfrom"pretender";constendpoint="https://jsonplaceholder.typicode.com/todos/1";newPretender(function(){this.get(endpoint,this.passthrough);});constxhr=newXMLHttpRequest();xhr.responseType="json";xhr.onload=()=>{constresponse=xhr.response;// expected to be 'object'console.log(typeofresponse);};xhr.open("GET",endpoint);xhr.send();
What it does is creates pretender instance with passthrough get endpoint and XMLHttpRequest with responseType = 'json'. After the xhr request is sent, the type of result is logged into console.
Expected result
Since xhr request's responseType is set to json the type of result should be object. You can observe this behaviour by deleting code, that creates pretender instance so that xhr requests are not routed through passthrough middleware but instead are handled directly by the browser. Actual result
Type of response is string
The text was updated successfully, but these errors were encountered:
Issue
Seems like pretender's
passthrough
does not take into account theresponseType
value that was set in originalXMLHttpRequest
object.The issue can be reproduced by the following snippet:
What it does is creates pretender instance with passthrough
get
endpoint and XMLHttpRequest withresponseType = 'json'
. After thexhr
request is sent, the type of result is logged into console.Expected result
Since
xhr
request'sresponseType
is set tojson
the type of result should beobject
. You can observe this behaviour by deleting code, that creates pretender instance so that xhr requests are not routed throughpassthrough
middleware but instead are handled directly by the browser.Actual result
Type of response is
string
The text was updated successfully, but these errors were encountered: