Book Image

Jasmine JavaScript Testing Update

By : Paulo Vitor Zacharias Ragonha
Book Image

Jasmine JavaScript Testing Update

By: Paulo Vitor Zacharias Ragonha

Overview of this book

Table of Contents (15 chapters)

Jasmine basics and thinking in BDD


Based on the application presented previously, we can start writing acceptance criteria that define investment:

  • Given an investment, it should be of a stock

  • Given an investment, it should have the invested shares' quantity

  • Given an investment, it should have the share price paid

  • Given an investment, it should have a cost

Using the standalone distribution downloaded in the previous chapter, the first thing we need to do is create a new spec file. This file can be created anywhere, but it is a good idea to stick to a convention, and Jasmine already has a good one: specs should be in the /spec folder. Create an InvestmentSpec.js file and add the following lines:

describe("Investment", function() {

});

The describe function is a global Jasmine function used to define test contexts. When used as the first call in a spec, it creates a new test suite (a collection of test cases). It accepts two parameters, which are as follows:

  • The name of the test suite—in this case...