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 #61

Closed
mroderick opened this issue Aug 7, 2018 · 3 comments
Closed

Filtered synchronous FakeXMLHttpRequest throw Exception #61

mroderick opened this issue Aug 7, 2018 · 3 comments

Comments

@mroderick
Copy link
Member


Migrated from sinonjs/sinon#1873
Originally created by @sebcanonica on Wed, 01 Aug 2018 17:16:00 GMT


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.

@mroderick
Copy link
Member Author


Migrated from sinonjs/sinon#1873 (comment)
Originally created by @lddubeau on Tue, 07 Aug 2018 17:52:58 GMT


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.

@stale
Copy link

stale bot commented Oct 6, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@fatso83
Copy link
Contributor

fatso83 commented Oct 14, 2018

Closed by #67

@fatso83 fatso83 closed this as completed Oct 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants