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
What did you expect to happen?
When a invalid xml file is loaded with XMLHttpRequest, the responseXML is null.
What actually happens
The FakeXMLHttpRequest fills the responseXML with the parsed xml document with included parseErrors.
How to reproduce
constinvalidXMLData=`!!!<?xml version="1.0" encoding="UTF-8"?><start>`;functiontestXMLRequest(options){varxhr=newXMLHttpRequest();xhr.open('GET',options.url,true);// If specified, responseType must be empty string or "document"xhr.responseType='document';// overrideMimeType() can be used to force the response to be parsed as XMLxhr.overrideMimeType('text/xml');xhr.onload=function(){if(xhr.readyState===xhr.DONE){if(xhr.status===200){if(xhr.responseXML){options.onSuccess();}else{options.onErrorCallback();}}}};xhr.send(null);}letxhr,requests,requestor;before(()=>{xhr=sinon.useFakeXMLHttpRequest();requests=[];xhr.onCreate=function(xhr){requests.push(xhr);};});after(()=>{xhr.restore();});it('Should throw an error, when the xml is invalid',()=>{letsuccessCallback=sinon.spy();leterrorCallback=sinon.spy();constreqSettings={url: '/xml',onSuccess: successCallback,onErrorCallback: errorCallback,};testXMLRequest(reqSettings);requests[0].respond(200,{'Content-Type': 'text/text'},invalidXMLData);expect(successCallback.notCalled,'Success callback is not called').to.be.true;expect(errorCallback.calledOnce,'Error callback is called').to.be.true;});
Solution
After parsing the response, you should check for parseerrors and return null.
The text was updated successfully, but these errors were encountered:
What did you expect to happen?
When a invalid xml file is loaded with XMLHttpRequest, the responseXML is null.
What actually happens
The FakeXMLHttpRequest fills the responseXML with the parsed xml document with included parseErrors.
How to reproduce
Solution
After parsing the response, you should check for parseerrors and return null.
The text was updated successfully, but these errors were encountered: