Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XMLHttpRequest's responseType json is ignored by passthrough #325

Open
jvalatkevicius opened this issue Jul 1, 2021 · 0 comments
Open

Comments

@jvalatkevicius
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant