JSON-P

JSON-P

JSON-P doesn’t use `XHR requests, which is what the fake server is concerned with. A JSON-P request creates a script element and inserts it into the document.

There is no sufficiently unobtrusive way to fake this automatically. The best option is to simply stub jQuery in this case:

sinon.stub(jQuery, "ajax");
sinon.assert.calledOnce(jQuery.ajax);

We could potentially have had the fake server detect jQuery and fake any calls to `jQuery.ajax when JSON-P is used, but that felt like a compromise in the focus of the Sinon project compared to simply documenting the above practice.

© 2010–2017 Christian Johansen
Licensed under the BSD License.
http://sinonjs.org/releases/v1.17.7/json-p

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部