Setting up unit testing with Jasmine and Karma
This section will give a brief overview of Jasmine (http://jasmine.github.io) and Karma (https://karma-runner.github.io). We will set up a testing environment before writing concrete unit tests. For this purpose, the Webpack seed project introduced in the Setting up PrimeNG project with Webpack section of Chapter 1, Getting Started with Angular and PrimeNG, will be extended.
Brief introduction to Jasmine
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...