Skip to content

Instantly share code, notes, and snippets.

@cjohansen
cjohansen / gist:739597
Created December 13, 2010 21:00
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 () {
@cjohansen
cjohansen / gist:739589
Created December 13, 2010 20:55
Showing how to fake server requests with Sinon.JS and Jasmine
/*
Load Sinon.JS in the SpecRunner:
<script type="text/javascript" src="lib/jasmine-1.0.1/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-1.0.1/jasmine-html.js"></script>
<script type="text/javascript" src="sinon-1.0.0.js"></script>
<script type="text/javascript" src="sinon-ie-1.0.0.js"></script>
http://cjohansen.no/sinon/
*/