Come posso testare onreadystatechange su XMLHttpRequest o puro Javascript AJAX senza jQuery? Lo sto facendo perché sto sviluppando l'estensione per Firefox. Credo di dover usare spie, ma non riesco a capire come, perché il mio ajax non restituirà nulla.Come testare XMLHttpRequest con Jasmine
submit : function() {
var url = window.arguments[0];
var request = new XMLHttpRequest();
request.open("POST", 'http://'+this.host+'/doSomething', true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.send("param="+param+"&emotions="+this.getParams());
request.onreadystatechange = function() {
if(this.readyState == 4) {
// alert(this.responseText);
}
};
}
possibile duplicato di [Come creare Stub per una funzione jax utilizzando Jasmine BDD] (http://stackoverflow.com/questions/8884060/how-to-create-stub-for-ajax-function-using-jasmine-bdd) –
Bene, quello sta usando jQuery, ma sto cercando di usare XMLHttpRequest puro. – toy
Certo, ma la risposta (usando il sinottico di SininJS) funziona anche per il tuo caso. –