Hi,
I am working on unit testing of my custom widget. I am unable to receive the response from XMLHttpRequest requests.Can some one please help me.Here I have copied a simple XML HTTP request.I am getting the same problem with dojoPromise response as well.
unit test method----
'Test getTravelModes':function(){
var defferd = this.async(1000);
testApp.getTravelModes().then(defferd.callback(
function(data) {
console.log(data);
assert.equal(response,8,'travel modes count matches');
}, function(err) {
console.log(err);
}));
}
widget method----
getTravelModes:function(){
var travelModes = [];
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
console.log(this.status + " " + this.readyState);
if (this.readyState == 4 && this.status == 200) {
if(this.responseText.indexOf("error") == -1){
for(var i=0;i<JSON.parse(this.responseText).supportedTravelModes.length;i++){
travelModes.push(JSON.parse(this.responseText).supportedTravelModes.name);
}
return travelModes;
}
};
}
xhr.open("POST", "https://hostname/rest/services/Routing/NetworkAnalysis/NAServer/Route_World/retrieveTravelModes",false);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
var chkParams = "token="+tokenValue+"&f=json";
xhr.send(chkParams);
}
Regards,
Sandhya
Hi, Can someone please help with this
Here is seriously only one or two people that have posted on Geonet about unit testing when it comes to widgets. So there is probably not going to much help from the community on this subject.