Created
May 5, 2011 16:41
-
-
Save gigasquid/957389 to your computer and use it in GitHub Desktop.
Example Spec File for Ajax Mocking with Jasmine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(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!