While utilizing the jasmine-ajax library for testing JavaScript code, I have discovered a way to mock ajax responses. There are essentially two methods to achieve this:
Method #1:
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'text/plain',
responseText: 'my response'
});
Method #2:
jasmine.Ajax.stubRequest('my/url').andReturn({
'responseText': 'my response'
});
If my mostRecent request corresponds to the url my/url, what sets these two approaches apart?
I first came across these techniques in M.E. Trostler's "JavaScript Unit Testing" video series, however, I am unable to find a definitive answer to my query in those videos, StackOverflow, or even in the Jasmine online documentation for its ajax.js plugin.