Skip to content

Commit c4d87ab

Browse files
authored
Merge pull request #234 from raido/abortable-fetch
Enable Abortable fetch
2 parents 6cdf4e5 + 597e707 commit c4d87ab

2 files changed

Lines changed: 4 additions & 34 deletions

File tree

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"./pretender.js"
1717
],
1818
"dependencies": {
19-
"FakeXMLHttpRequest": "^1.6.0",
19+
"FakeXMLHttpRequest": "^2.0.1",
2020
"route-recognizer": "^0.2.3"
2121
},
2222
"devDependencies": {

test/fetch_test.js

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -63,37 +63,7 @@ describe('pretender invoking by fetch', function(config) {
6363
return wait;
6464
});
6565

66-
67-
// TODO: Pretender doesn't work with abortable fetch
68-
// src in fake_xml_http_request.js
69-
// ```
70-
// abort: function abort() {
71-
// this.aborted = true;
72-
// this.responseText = null;
73-
// this.errorFlag = true;
74-
// this.requestHeaders = {};
75-
76-
// if (this.readyState > FakeXMLHttpRequest.UNSENT && this.sendFlag) {
77-
// this._readyStateChange(FakeXMLHttpRequest.DONE);
78-
// this.sendFlag = false;
79-
// }
80-
81-
// this.readyState = FakeXMLHttpRequest.UNSENT;
82-
83-
// this.dispatchEvent(new _Event("abort", false, false, this));
84-
// if (typeof this.onerror === "function") {
85-
// this.onerror();
86-
// }
87-
// }
88-
// ```
89-
// For `fake_xml_http_request` impl, the request is resolved once its state
90-
// is changed to `DONE` so the `reject` is not cathed.
91-
// So the senario happens in pretender is:
92-
// 1. state chagne to `DONE`, trigger resolve request
93-
// 2. abort, trigger reject
94-
// 3. xhr.onerror, trigger reject
95-
// The first resolve wins, error thus not rejected but an empty request is resolved.
96-
it('has NO Abortable fetch', function(assert) {
66+
it('has Abortable fetch', function(assert) {
9767
assert.expect(1);
9868
this.pretender.get(
9969
'/downloads',
@@ -110,8 +80,8 @@ describe('pretender invoking by fetch', function(config) {
11080
}, 10);
11181

11282
return fetch('/downloads', { signal: signal })
113-
.then(function(data) {
114-
assert.ok(data, 'AbortError was not rejected');
83+
.catch(function(err) {
84+
assert.equal(err.name, 'AbortError');
11585
});
11686
});
11787
});

0 commit comments

Comments
 (0)