Last active
December 16, 2015 04:39
-
-
Save karanparikh/5378784 to your computer and use it in GitHub Desktop.
Async Jasmine Test
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('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