Trying to write a test for our XmlhttpRequests I am trying to test the following
getMove(){
var image = 'placeholder'
let url = `http://localhost:8000/pong/bot?&bally=${Math.round(this.ball.position.y)}&paddley=${this.players[1].position.y}&reward=${this.aggregateReward}&img=${image}`
var that = this
var xmlhttp = new XMLHttpRequest()
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var myArr = JSON.parse(this.responseText);
that._move = myArr['up'];
that.botUpdate(that._move);
that.responseReceived = true;
}
};
xmlhttp.open('GET', url, true);
xmlhttp.send();
}
Trying to mock the request so (is this the correct idea?) I wrote this test for it
describe("getMove", function() {
it("should communicate data with XHR request", function() {
var xhr = {
open: jasmine.createSpy('open')
};
XMLHttpRequest = jasmine.createSpy('XMLHttpRequest');
XMLHttpRequest.and.callFake(function () {
return xhr;
});
submit();
expect(xhr.open).toHaveBeenCalled();
})
})
However I get a submit is not defined, am confused as to whats happening here
Aucun commentaire:
Enregistrer un commentaire