Angular test setup

When creating a project using the Angular-CLI (by issuing an ng new command), the default project setup already includes all of the boilerplate code to run unit tests using Karma, and end-to-end tests using Protractor. This default setup is a very handy feature of Angular, shortening the development effort of configuring a test environment, and giving us the ability to dive right in and write tests from the beginning of a project.

To run unit tests using Karma, we can type the following from the command line:

ng test 

This command-line option will compile and package our application, and run any tests that it finds within the src directory. Any TypeScript file where the name matches *.spec.ts will be designated as a test ...

Get Mastering TypeScript 3 - Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.