Ionic Testing

Not yet Complete

In Ionic we need two kinds of tests:

  1. Unit tests – Test a single unit, for example, a component, a service, or a pipe.
  2. End-to-end tests (Browser-Only) – Usually for testing integration between different units.

In a Javascript environment, the Jasmine framework is typically used for writing tests and Karmto run tests on different browsers. This is still the case for testing Ionic 2 applications, but Angular 2 has introduced the concept of the TestBed. Since Ionic 2 applications are built on top of Angular 2, we can also make use of TestBed in our Ionic 2 applications.

Note: We have to update ionic Ionic 3.4.2 and Angular 4.1.3

We need to install the dependency as

npm install --save-dev @angular/cli @angular/router @types/jasmine @types/node jasmine-core jasmine-spec-reporter karma karma-chrome-launcher karma-cli karma-jasmine karma-jasmine-html-reporter karma-coverage-istanbul-reporter
npm add --only=dev angular-cli

Testing Configuration

Our Ionic app is not created using Angular 2 CLI, so we need to add the angular-cli.json in the root directory to make Angular 2 CLI recognize it as an Angular 2 app.