I think some things are black and white: It’s Michael.
To start with Jasmine, you need to create the following structure in your project:
Where you can find the following components:
- SpecRunner.html: it’s the file you have to execute to lanch the tests. It’s an HTML that will be opened in the browser displaying the passed and failed tests.
- Lib: folder which contains the libraries and files that Jasmine needs.
- Spec: in this folder you can find all the tests definitions.
To make sure that it works, we’re going to develop some tests for this clase. For example:
In the previous test file, we have implemented three different tests (it). The first two are valid but not the third.
Finally, we only have to execute the runner file, in which we need to include all the sources that contain the code to test, and the files with the test cases. In this case the runner will be the following:
After executing this file, we can see the following report in our browser. You can see the passed tests in green and the failed ones in red, with all the related information, like stack traces and error location etc
That’s all folks. Enjoy testing!by