Skip to content

Instantly share code, notes, and snippets.

@karanparikh

karanparikh/test.js

Last active Dec 16, 2015
Embed
What would you like to do?
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
You can’t perform that action at this time.