Testing Ajax Event Handlers using Jasmine Spies

JavaScript has several methods that execute asynchronously, such as setTimeout(), Ajax calls, as well as event-driven processes. These examples all have to wait until the current execution thread comes to an end and surrenders to the next event, making asynchronous processes hard to test. Fortunately, the Jasmine JS testing library comes equipped with a couple of tools for handling callbacks.