入口组件的Angular 2单元测试错误

时间:2017-10-17 08:52:38

标签: angular unit-testing

我需要在我的组件中测试几个方法。我现在不需要测试该入口组件或相关功能,但在尝试测试“父”组件时遇到错误。

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可以让我摆脱这种情况。我怎样才能让我的测试工作?

0 个答案:

没有答案