我需要在我的组件中测试几个方法。我现在不需要测试该入口组件或相关功能,但在尝试测试“父”组件时遇到错误。
Error: Component OrderReportsTableComponent is not part of any NgModule or the module has not been imported into your module. in config/spec-bundle.js (line 74723)
测试:
import {NO_ERRORS_SCHEMA} from '@angular/core';
import {inject} from '@angular/core/testing';
import {async} from '@angular/core/testing';
import {TestBed} from '@angular/core/testing';
import {ComponentFixture} from '@angular/core/testing';
import {OrderReportsChartComponent} from '../../order-reports-chart.component';
import {OrderReportsTableComponent} from '../../../table/order-reports-table.component';
describe(`order-reports-chart.component.ts`, () => {
let comp: OrderReportsChartComponent;
let fixture: ComponentFixture<OrderReportsChartComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ OrderReportsChartComponent ],
schemas: [NO_ERRORS_SCHEMA]
})
}));
beforeEach(() => {
fixture = TestBed.createComponent(OrderReportsChartComponent);
comp = fixture.componentInstance;
fixture.detectChanges();
});
it(`should be initialized`, () => {
expect(fixture).toBeDefined();
expect(comp).toBeDefined();
});
});
我不需要这个OrderReportsTableComponent
的东西,但它只是在错误中弹出。它与NgModule
的{{1}}相同,但它是后者的入口组件。我认为使用OrderReportsChartComponent
可以让我摆脱这种情况。我怎样才能让我的测试工作?