Skip to content

Instantly share code, notes, and snippets.

Last active Dec 16, 2015
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.
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() {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment