Skip to content

Instantly share code, notes, and snippets.

@cjohansen
Created December 13, 2010 21:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjohansen/739597 to your computer and use it in GitHub Desktop.
Save cjohansen/739597 to your computer and use it in GitHub Desktop.
Mocking jQuery.ajax with Sinon.JS
describe("SinonMockJQAjaxWithJasmine", function() {
it("should mock a jQuery ajax request", sinon.test(function () {
this.mock(jQuery).expects("ajax").once();
jQuery.ajax({
url: "/something"
});
}));
it("should fail when expectations are not met", sinon.test(function () {
this.mock(jQuery).expects("ajax").twice();
jQuery.ajax({
url: "/something"
});
}));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment