Skip to content

Commit b33a387

Browse files
authored
Merge pull request #300 from PolymerElements/timeout-set-undef-async
opts.async is undef sets timeout
2 parents 536c76a + a389c33 commit b33a387

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

iron-request.html

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@
8585
* if there is an error before the `xhr` completes.
8686
* The resolve callback is called with the original request as an argument.
8787
* By default, the reject callback is called with an `Error` as an argument.
88-
* If `rejectWithRequest` is true, the reject callback is called with an
89-
* object with two keys: `request`, the original request, and `error`, the
88+
* If `rejectWithRequest` is true, the reject callback is called with an
89+
* object with two keys: `request`, the original request, and `error`, the
9090
* error object.
9191
*
9292
* @type {Promise}
@@ -267,10 +267,11 @@
267267
}.bind(this));
268268

269269
this.url = options.url;
270+
var isXHRAsync = options.async !== false;
270271
xhr.open(
271272
options.method || 'GET',
272273
options.url,
273-
options.async !== false
274+
isXHRAsync
274275
);
275276

276277
var acceptType = {
@@ -300,10 +301,8 @@
300301
);
301302
}, this);
302303

303-
if (options.async !== false) {
304-
if (options.async) {
305-
xhr.timeout = options.timeout;
306-
}
304+
if (isXHRAsync) {
305+
xhr.timeout = options.timeout;
307306

308307
var handleAs = options.handleAs;
309308

test/iron-request.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@
8484
async: true,
8585
timeout: 100
8686
};
87+
88+
asynchronousUndefSuccessfulRequestOptions = {
89+
url: '/responds_to_get_with_json',
90+
async: undefined,
91+
timeout: 100
92+
};
8793
});
8894

8995
teardown(function() {
@@ -106,8 +112,8 @@
106112
expect(request.xhr.timeout).to.be.eql(undefined);
107113
});
108114

109-
test('timeout set if asynchronous', function() {
110-
request.send(asynchronousSuccessfulRequestOptions);
115+
test('timeout set if asynchronous is undefined', function() {
116+
request.send(asynchronousUndefSuccessfulRequestOptions);
111117

112118
expect(request.xhr.async).to.be.eql(true);
113119
expect(request.xhr.timeout).to.be.eql(100);

0 commit comments

Comments
 (0)