Getting started with Jasmine
To write tests, you should create two things: test suites and specs. A spec (short for specification) is a piece of functionality that you are testing from your code; for example, if your code is calculating tax of 5% for $100.00, you would expect it to be $5. A test suite is a set of expectations that are grouped under a topic. In the preceding example, the test suite can be "Invoice totals calculation".
To start working with Jasmine, you should install it from npm, as follows:
$ npm install --save-dev jasmine
Then, you can start writing your tests. With Jasmine, you have two functions: describe()
to create test suites and it()
to make specs:
// specs/mathSpec.js describe('Basic mathematicfunctions', () => { it('should result 4 the sum of 2 + 2', () => { }); it('should result 1 the substract of 3 - 2', () => { }); it('should result 3 the division of 9 / 3', () => { }); it('should throw an error when divide by zero', () => { }); });
The...