What the ajax call is doing is returning something call a promise
.
There are various articles you can look on this regards:
- How to properly unit test jQuery's .ajax() promises using Jasmine and/or Sinon?
- JavaScript with Promises and Jasmine
- Stubbing Out $.ajax in Jasmine
But bottom line here are some sample code on how to achieve this:
spyOn( $, 'ajax' ).andCallFake( function (params) {
params.success({foo: 'bar'});
});
spyOn( $, "ajax" ).andCallFake( function (params) {
params.error({foo: "bar"});
});