Jasmine is a JavaScript testing framework with zero dependencies. With npm, you can install it as follows:
npm install jasmine-core --save-dev
You also need to install the Jasmine type definition file. Otherwise, the TypeScript compiler will not know about the Jasmine types.
npm install @types/jasmine --save-dev
Jasmine has four main concepts:
- Specs: In Jasmine terminology, unit tests are called specs. The it(string, function) function specifies a test. It takes a title and a function containing one or more expectations.
- Suites: Specs are wrapped in suites. The describe(string, function) function describes a test suite. It takes a title and a function containing one or more specs. Suit can contain other nested suites as well.
- Expectations: These are assertions which are specified using the expect(actual) function. The function gets one argument--the actual value.
- Matchers: Assertions are followed by matchers. Jasmine has a lot of matchers such as toBe(expected...