Chapter 2. Your First Spec

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.

The Investment Tracker application

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:

The Investment Tracker application

This is a form to add investments

This form will allow the input of three values that define an investment:

  • First, we will input Symbol, which represents which company (stock) the user is investing in
  • Then, we will input how many Shares the user has bought (or invested in)
  • Finally, we will input how much the user has paid for each share (Share price)

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:

  • A stock, which is defined by a symbol, such as PETO, can be understood to be a grocery type
  • The number of shares is the quantity of items you have purchased
  • The share price is the unit price of each item

Once the user has added an investment, it must be listed along with their other investments, as shown in the following screenshot:

The Investment Tracker application

This is a form and list of investments

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:

  • One is in the AOUE stock, which is scoring a profit of 101.80%
  • Another is in the 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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset