非法状态:无法加载指令 AppComponent 的摘要

Arp*_*pta 3 angular6

我正在用 Angular 编写一个 spec.ts 文件并收到以下错误:

失败:非法状态:无法加载指令 AppComponent 的摘要。

下面是我尝试过的代码

import { TestBed, async } from "@angular/core/testing";
    import { AppComponent } from "./app.component";

    describe('AppComponent', () => {
        beforeEach(() => {
            TestBed.configureTestingModule({
                declarations: [
                    AppComponent
                ],
            });
        });
    });

    it('should create the app', async(() => {
        let fixture = TestBed.createComponent(AppComponent);
        let app = fixture.debugElement.componentInstance;
        expect(app).toBeTruthy();
    }));``
Run Code Online (Sandbox Code Playgroud)

Nim*_*ard 5

看来您正在使用一个内部包含另一个组件的组件。您必须添加您在AppComponent中使用的所有组件declarationconfigureTestingModule