You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
loadFile(url: string): Promise<ArrayBuffer>{returnnewPromise((resolve,reject)=>{constxhr=newXMLHttpRequest();xhr.responseType='arraybuffer';xhr.open('GET',url,true);xhr.onload=()=>{if(xhr.readyState===4&&xhr.status===200){resolve(xhr.response);}else{reject(newError('get failed with status '+xhr.status));}};xhr.onerror=(err)=>reject(err);xhr.send();});}
In the browser, the response data is in xhr.response (not xhr.responseType!)) as an ArrayBuffer, and accessing xhr.responseText throws an exception. In the mock, the data is a string in xhr.responseText but xhr.response is null.
In my (jest) test I mock XHR like this:
I use
XMLHTTPRequest
in my code in like this:In the browser, the response data is in
xhr.response
(notxhr.responseType
!)) as anArrayBuffer
, and accessingxhr.responseText
throws an exception. In the mock, the data is a string inxhr.responseText
butxhr.response
isnull
.This looks like a bug to me, see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Handling_binary_data. Any chance to fix this?
The text was updated successfully, but these errors were encountered: