Skip to content
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'];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var evts = ['error', 'timeout', 'abort', 'readystatechange','loadend'];
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