-
Notifications
You must be signed in to change notification settings - Fork 158
Open
Description
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:
import Pretender from "pretender";
const endpoint = "https://jsonplaceholder.typicode.com/todos/1";
new Pretender(function () {
this.get(endpoint, this.passthrough);
});
const xhr = new XMLHttpRequest();
xhr.responseType = "json";
xhr.onload = () => {
const response = xhr.response;
// expected to be 'object'
console.log(typeof response);
};
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
rohitpaulk
Metadata
Metadata
Assignees
Labels
No labels