Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/create-passthrough.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ export function createPassthrough(fakeXHR, nativeXMLHttpRequest) {
xhr.timeout = fakeXHR.timeout;
xhr.withCredentials = fakeXHR.withCredentials;
}
// XMLHttpRequest.timeout default initializes to 0, and is not allowed to be used for
// synchronous XMLHttpRequests requests in a document environment. However, when a XHR
// polyfill does not sets the timeout value, it will throw in React Native environment.
// TODO:
// synchronous XHR is deprecated, make async the default as XMLHttpRequest.open(),
// and throw error if sync XHR has timeout not 0
if (!xhr.timeout) {
xhr.timeout = 0; // default XMLHttpRequest timeout
}
for (var h in fakeXHR.requestHeaders) {
xhr.setRequestHeader(h, fakeXHR.requestHeaders[h]);
}
Expand Down
5 changes: 2 additions & 3 deletions test/passthrough_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe('passthrough requests', function(config) {
}
);

it('synchronous request does not have timeout, withCredentials and onprogress event', function(
it('synchronous request has timeout=0, withCredentials and onprogress event', function(
assert
) {
var pretender = this.pretender;
Expand All @@ -125,7 +125,7 @@ describe('passthrough requests', function(config) {
this.send = {
pretender: pretender,
apply: function(xhr/*, argument*/) {
assert.ok(!('timeout' in xhr));
assert.equal(xhr.timeout, 0);
assert.ok(!('withCredentials' in xhr));
assert.ok(!('onprogress' in xhr));
this.pretender.resolve(xhr);
Expand All @@ -139,7 +139,6 @@ describe('passthrough requests', function(config) {

var xhr = new window.XMLHttpRequest();
xhr.open('POST', '/some/path', false);
xhr.timeout = 1000;
xhr.withCredentials = true;
xhr.send('some data');
});
Expand Down