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

Filtered synchronous FakeXMLHttpRequest throw Exception #1873

Closed
sebcanonica opened this issue Aug 1, 2018 · 2 comments
Closed

Filtered synchronous FakeXMLHttpRequest throw Exception #1873

sebcanonica opened this issue Aug 1, 2018 · 2 comments

Comments

@sebcanonica
Copy link

Symptom
Using a fake server, if I try to filter a request (to let it go through normally) which is sent synchronously, then sinon throw an exception:

In Chrome
Uncaught DOMException: Failed to set the 'responseType' property on 'XMLHttpRequest': The response type cannot be changed for synchronous requests made from a document.
at y.u.send (https://cdnjs.cloudflare.com/ajax/libs/sinon.js/6.1.4/sinon.min.js:1:113357)
at window.onload (https://fiddle.jshell.net/_display/:36:9)

In Firefox
InvalidAccessError: synchronous XMLHttpRequests do not support timeout and responseType. sinon.min.js:1
[61]</</y.defake/u.send
https://cdnjs.cloudflare.com/ajax/libs/sinon.js/6.1.4/sinon.min.js:1:113343
window.onload
https://fiddle.jshell.net/_display/:36:1

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://jsfiddle.net/sebcano/czmhLrqf/7/
  2. Open the console
  3. Click on Run
  4. See error
const server = sinon.fakeServer.create();
server.xhr.useFilters = true;
server.xhr.addFilter(() => true);
const request = new XMLHttpRequest();
request.open('GET', 'anything.html', false);
request.send();
console.log('Not reached');

Expected behavior
The request should be served normally and no exception should be thrown

Context

Additional context
The defake method put in place a send method which modify the responseType of the real xhr, which is forbidden for synchronous xhr not in a worker context.
If I comment out this line, the behavior is Ok.

@lddubeau
Copy link

lddubeau commented Aug 7, 2018

I confirm having the same problem if I run Sinon 6. The problem goes away if I revert to the latest in the 5.x series.

The change was introduced by this PR in nise, which then made its way to Sinon.

@mroderick
Copy link
Member

Issue migrated to sinonjs/nise#61

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

3 participants