So we've got this weird frontend at our company written with AngularJS and I have the pleasure of writing automated tests for our new CI setup with Jasmine. However at the moment I'm not even trying to test the frontend, I just wanna get Jasmine to send out a simple ajax-call and print out the result.
I've tried this: https://coderwall.com/p/pbsi7g/testing-ajax-calls-with-jasmine-2 and this: How do I verify jQuery AJAX events with Jasmine? this: Mocking jQuery ajax calls with Jasmine and many more.
So here's my current code:
it('test', function (done) {
jasmine.Ajax.install();
$.ajax({
url: "http://5da98016de10b40014f37142.mockapi.io/api/networks",
contentType: "application/json",
dataType: "json",
success: function(result){
console.log(result);
expect(result).toBeDefined();
done();
},
error: function(){
console.log("ERROR");
done();
}
});
});
I've tried putting the call in a seperate function outside the "it()", using a variable to write the result of the call to and checking its value...
However its always the same problem. Jasmine straight up ignores the call and wont even enter the $.ajax() function.
I am pretty new to the topic of writing tests, never used jasmine before yesterday so have mercy if I'm just totally forgetting anything here.
Aucun commentaire:
Enregistrer un commentaire