Skip to content

Instantly share code, notes, and snippets.

@gigasquid
Created May 5, 2011 16:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gigasquid/957389 to your computer and use it in GitHub Desktop.
Save gigasquid/957389 to your computer and use it in GitHub Desktop.
Example Spec File for Ajax Mocking with Jasmine
describe("Mocking Ajax Calls", function() {
beforeEach(function() {
loadFixtures('test.html');
//mocking ajax call with Jasmine Spies
var fakeData = "You can put your return data here";
spyOn($, "ajax").andCallFake(function(params) {
params.success(fakeData);
});
});
it("Should have a Happy Face", function() {
mymethod();
expect($('#mydiv')).toHaveText("Happy Face");
});
});
@jdugarte
Copy link

jdugarte commented May 1, 2013

(I'm posting this comment here because comments in your blog post are closed)

I struggled to make fake ajax calls work (tried jasmine-fake-ajax and jasmine-ajax) but your solution worked just great.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment