[Angular] Using NO_ERRORS_SCHEMA

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 }
      ]
    });

 

Related Posts

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注