Vishnu
Vishnu

Reputation: 4687

jasmine-ajax mock get parameters

I am using jasmine-ajax to mock $.ajax get calls. In my actual code I send some parameters through the data options.

var request = $.ajax("/users", {
      data: {id:"1"},
});

but in my tests jasmine.Ajax.requests.mostRecent().url returns /users?id=1 and jasmine.Ajax.requests.mostRecent().data() returns {}. Is there a way to make the url return /users and data return {id:"1"} to make my testing life easier?

Upvotes: 0

Views: 301

Answers (1)

When using GET method for making a request, the query string is sent like this /users?id=1. But you should use POST method if you want to make your "testing life easier".

var request = $.ajax("/users", {
    method: "POST",
    data: {id:"1"},
});

See the resulting specs in this jsfiddle: https://jsfiddle.net/EduardoRG/49ufpe3b/

Upvotes: 0

Related Questions