Skip to content

Commit

Permalink
feat(xhr): allows mocking xhr request with invalid status response
Browse files Browse the repository at this point in the history
  • Loading branch information
Arturo Riveron Borodovisina committed Mar 14, 2022
1 parent 8db00dd commit 8e28840
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/xhr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}
Object.values(this._eventHandlers).flat().forEach(handler => {
handler.call(this);
});

let callback = this.onreadystatechange || this.onload;

Expand Down

0 comments on commit 8e28840

Please sign in to comment.