How to fake jquery.ajax() response?

前端 未结 6 505
孤独总比滥情好
孤独总比滥情好 2020-12-07 20:56

I am writing some QUnit tests for a JavaScript that makes AJAX calls.

For isolation I overwrite $.ajax to write the parameter array of an AJAX call to a

6条回答
  •  情歌与酒
    2020-12-07 21:19

    Look at the jQuery documentation: You'll see that the Ajax setup provides a number of other conditions that are tested for. If you make them all point to your fakeAjaxSuccess, you might achieve for your objective.

    Alternatively, wrap your $.ajax call into its own function and have whatever calls it simply call your event handler with the fakeAjaxSuccess object.

提交回复
热议问题