var server;
describe("Catch ajax request and test Url", function () {
before(function () { server = sinon.fakeServer.create(); });
after(function () { server.restore(); });
it("should be google", function () {
jQuery.ajax({
url: "www.google.de",
success: function (data) {
callback(null, data);
}
});
// test the issued url against it expectation
expect(server.requests[0].url).to.be("www.google.de");
});
});
describe("Test how many ajax calls where issued", function () {
var server;
before(function () { server = sinon.fakeServer.create(); });
after(function () { server.restore(); });
// test code
var testF = function () {
jQuery.ajax({ url: "www.google.de" });
jQuery.ajax({ url: "www.google.de" });
jQuery.ajax({ url: "www.google.de" });
jQuery.ajax({ url: "www.google.de" });
};
it("should called 4 times to google", function () {
testF();
// test the issued url against it expectation
expect(server.requests.length).to.be(4);
});
});
describe("Test the Ajax request and provide a response", function () {
before(function () { server = sinon.fakeServer.create(); });
after(function () { server.restore(); });
it("of $.ajax", function () {
var callback = sinon.spy();
$.support.cors = true;
jQuery.ajax({
url: "http://localhost:10001/api/sm5/report/testreportparameter",
success: function (data) {
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.