For example, when testing container component we might import lots of children components, but we didn't actually testing those children components. So we don't need to provide all those stuff:

    TestBed.configureTestingModule({
      imports: [
        ReactiveFormsModule
      ],
      declarations: [
        StockBranchComponent,
        StockCounterComponent,
        StockProductsComponent,
        StockSelectorComponent,
        StockInventoryComponent
      ],
      providers: [
        {provide: StockInventoryService, useClass: MockStockInventoryService }
      ]
    })

 

One way to sovle this is by providing '

NO_ERRORS_SCHEMA

'

import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';

    TestBed.configureTestingModule({
      imports: [
        ReactiveFormsModule
      ],
      declarations: [
        StockInventoryComponent
      ],
      schemas: [NO_ERRORS_SCHEMA],
      providers: [
        { provide: StockInventoryService, useClass: MockStockInventoryService }
      ]
    });

 

相关文章: