Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@karanparikh
Last active December 16, 2015 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karanparikh/5378784 to your computer and use it in GitHub Desktop.
Save karanparikh/5378784 to your computer and use it in GitHub Desktop.
Async Jasmine Test
describe('A Jasmine test', function() {
it('should be able to test async functions', function() {
// variable to check if our function call was successful
var wasSuccessful = null;
// Dummy Backbone model
var testModel = new TestModel();
runs(function() {
// someAsyncFunction is an async function that calls the 'success' function in our params object
// if the call was successful. It calls the 'error' function in our params object otherwise.
testModel.someAsyncFunction({
data: 'test',
success: function() {
wasSuccessful = true;
},
error: function() {
wasSuccessful = false;
}
});
});
var timeout = 2000;
waitsFor(function() {
return wasSuccessful;
}, 'Async call should be a success', timeout);
runs(function() {
expect(wasSuccessful).toBe(true);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment