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

Fix passthrough issue for libraries using loadend instead of onreadystatechange (Axios) #355

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/create-passthrough.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export function createPassthrough(fakeXHR, nativeXMLHttpRequest) {
// event types to handle on the xhr
var evts = ['error', 'timeout', 'abort', 'readystatechange'];
var evts = ['error', 'timeout', 'abort', 'readystatechange','loadend'];

// event types to handle on the xhr.upload
var uploadEvents = [];
Expand Down
15 changes: 14 additions & 1 deletion test/passthrough_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ describe('passthrough requests', function (config) {
});

it('asynchronous request fires events', function (assert) {
assert.expect(6);
assert.expect(8);

var pretender = this.pretender;
var done = assert.async();
Expand All @@ -192,11 +192,13 @@ describe('passthrough requests', function (config) {
load: false,
progress: false,
readystatechange: false,
loadend: false
};
var listenerEvents = {
load: false,
progress: false,
readystatechange: false,
loadend: false
};

var xhr = new window.XMLHttpRequest();
Expand Down Expand Up @@ -234,6 +236,15 @@ describe('passthrough requests', function (config) {
}
};

xhr.addEventListener('loadend', function _loadend() {
listenerEvents.loadend = true;
finishNext();
});

xhr.onloadend = function _onloadend() {
onEvents.loadend = true;
finishNext();
};
xhr.send();

// call `finish` in next tick to ensure both load event handlers
Expand All @@ -250,13 +261,15 @@ describe('passthrough requests', function (config) {
assert.ok(onEvents.load, 'onload called');
assert.ok(onEvents.progress, 'onprogress called');
assert.ok(onEvents.readystatechange, 'onreadystate called');
assert.ok(onEvents.loadend, 'loadend called');

assert.ok(listenerEvents.load, 'load listener called');
assert.ok(listenerEvents.progress, 'progress listener called');
assert.ok(
listenerEvents.readystatechange,
'readystate listener called'
);
assert.ok(listenerEvents.loadend, 'loadend listener called');

done();
}
Expand Down