Common Testing Module

Now that we have a lot of modules to deal with, it becomes tedious to configure the imports and providers for each spec file individually. For this purpose, I recommend creating a common testing module to contain generic configuration that you can reuse across the board.

First start by creating a new .ts file.

  1. Create common/common.testing.ts
  2. Populate it with common testing providers, fakes and modules, shown as follows:

I have provided fake implementations of ObservableMedia, MatIconRegistry, DomSanitizer, along with arrays for commonTestingProviders and commonTestingModules.

src/app/common/common.testing.tsimport { HttpClientTestingModule } from '@angular/common/http/testing'import { MediaChange } from '@angular/flex-layout' ...

Get Angular 6 for Enterprise-Ready Web Applications 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.