Chapter 2. Your First Spec

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.

The Investment Tracker application

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:

The Investment Tracker application

Form to add investments

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

  • A Symbol which represents what company (stock) the user is investing in
  • How many Shares the user has bought (or invested in)
  • How much the user has paid for each share (the Share price)

Tip

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:

  • 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 his or her other investments.

The Investment Tracker application

Form and list of 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:

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