From bebbed2fe40017fd70229fa529147c6a2b6aaad3 Mon Sep 17 00:00:00 2001 From: Arturo Riveron Borodovisina Date: Mon, 14 Mar 2022 18:49:18 +0100 Subject: [PATCH] feat(xhr): allows mocking xhr request with invalid status response --- src/xhr.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/xhr.js b/src/xhr.js index e49fb90..4c28993 100644 --- a/src/xhr.js +++ b/src/xhr.js @@ -10,7 +10,7 @@ export function $mockEndpoint(options) { options.uri = options.uri.replace(/\?/g, '\\?'); } - this.status = options.status || 200; + this.status = options.status !== undefined ? options.status : 200; this.rawMethod = options.method.toString(); this.rawUri = options.uri.toString(); @@ -221,11 +221,9 @@ SyncXMLHttpRequest.prototype = { this.response = this.responseText = JSON.stringify(response); this.readyState = 4; - if (this._eventHandlers.load) { - for (let handler of this._eventHandlers.load) { - handler.call(this); - } - } + for (let handler of Object.values(this._eventHandlers).flat()) { + handler.call(this); + }; let callback = this.onreadystatechange || this.onload;