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 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 only documenting the above practice.

© 2010–2020 Christian Johansen
Licensed under the BSD License.
https://sinonjs.org/releases/v8.1.1/json-p