This chapter is about the basics. We are going to guide you through how to write your first spec, thinking in test first, and also show all the available global Jasmine functions. By the end of the chapter, you should know how Jasmine works and be ready to start doing your first tests by yourself.
To get you started, we need an example scenario: consider you are developing an application to track investments in the stock market.
The following form illustrates better how a user might create a new investment on this application:
This form will allow the input of three values that define an investment:
Downloading the example code
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
If you are unfamiliar with how the stock market works, imagine you are shopping for groceries. To make a purchase you must specify what you are buying, how many items you are buying, and how much you are going to pay. These concepts translate to an investment as:
Once the user has added an investment, it must be listed along with his or her other investments.
The idea is to display how well his or her investments are going. Since the prices of the stocks fluctuate over time, the difference between the price the user has paid and the current price, indicate whether it is a good (profit) or a bad (loss) investment.
In the preceding figure, we can see that the user has two investments:
This is a very simple application and we will get a deeper understanding of its functionality as we go on with its development.