Writing unit tests

Now that we have the required setup, we are going to start writing the unit tests. Unit tests are written in a file next to the source file with .spec added to the filename. For example, if we are writing test cases for app.component.ts, we would create a file named app.component.spec.ts in the same folder and write the required test cases.

Refer to https://angular.io/docs/ts/latest/guide/testing.html#!#q-spec-file-location and https://angular.io/docs/ts/latest/guide/style-guide.html#!#02-10 for more information.

First, we would start off by writing tests for the app component. We are going to test the following cases:

  • If the component has been created.
  • If rootPage is set as LoginPage.

Now, create a file named app.component.spec.ts ...

Get Learning Ionic - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.