Now, the question that comes to mind is how to test asynchronous (Ajax) JavaScript code using Jasmine. What was mentioned in the chapter so far is how to perform unit testing for synchronous JavaScript code. Jasmine fortunately includes powerful functions (runs()
, waits()
, and waitsFor()
) for performing real Ajax testing (which requires the backend server to be up and running in order to complete the Ajax tests), and it also provides a mechanism for making fake Ajax testing (which does not require the availability of the backend server in order to complete the Ajax tests).
The code inside the runs()
block runs directly as if it were outside the block. The main purpose of the runs()
block is to work with the waits()
and waitsFor()
blocks to handle the testing of the asynchronous operations.
The runs()
block has some characteristics that are important to know. The first point is that, if you have multiple runs()
blocks in your spec...