Setting up the unit test environment
In this section, we will learn how to set up the test environment, and run the first unit test (written using Jasmine) with the Karma test runner.
The Angular app, when set up using the recommended methods such as those mentioned at https://angular.io/guide/setup, one of which was discussed in the Chapter 6, Getting Started with Angular, results in the installation of appropriate npm packages, files, and scripts, which can be used for writing and running unit tests with the Angular testing utilities Jasmine and Karma.Â
Perform the following steps to get started with running your first unit test:
- Create a file under the app folder, and name itÂ
helloworld.spec.ts
. - Place the following code in the file:
describe('Hello World',()=>{ it('unit tests are good',()=> expect(true).toBe(true)); });
- Go to the root folder of the app in Command Prompt.
- Execute the following command; (it concurrently runs the command
npm run build:watch
and...