From fd285df63c905fa77a94e4acd87f6dcd4d7db2c9 Mon Sep 17 00:00:00 2001 From: Drew Cerny Date: Mon, 27 Jun 2022 10:10:35 -0500 Subject: [PATCH] passthrough loadend event --- src/create-passthrough.ts | 2 +- test/passthrough_test.js | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/create-passthrough.ts b/src/create-passthrough.ts index 0ed7d9a..73f6dd1 100644 --- a/src/create-passthrough.ts +++ b/src/create-passthrough.ts @@ -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 = []; diff --git a/test/passthrough_test.js b/test/passthrough_test.js index b7d6277..b9eccd4 100644 --- a/test/passthrough_test.js +++ b/test/passthrough_test.js @@ -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(); @@ -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(); @@ -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 @@ -250,6 +261,7 @@ 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'); @@ -257,6 +269,7 @@ describe('passthrough requests', function (config) { listenerEvents.readystatechange, 'readystate listener called' ); + assert.ok(listenerEvents.loadend, 'loadend listener called'); done(); }