This chapter is about the basics, and we are going to guide you through how to write your first spec, think in test-first terms for development, and also show you 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 that you are developing an application to track investments in the stock market.
The following screenshot of the form illustrates how a user might create a new investment on this application:
This form will allow the input of three values that define an investment:
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:
PETO
, can be understood to be a grocery typeOnce the user has added an investment, it must be listed along with their other investments, as shown in the following screenshot:
The idea is to display how well their 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 indicates whether it is a good (profit) or a bad (loss) investment.
In the preceding screenshot, we can see that the user has two investments:
AOUE
stock, which is scoring a profit of 101.80%
PETO
stock, which is scoring a loss of -42.34%
This is a very simple application, and we will get a deeper understanding of its functionality as we go on with its development.