angular6 - 非法状态 : Could not load the summary for directive AppComponent

标签 angular6

我正在以 angular 编写 spec.ts 文件并收到以下错误:

Failed: Illegal state: Could not load the summary for directive 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();
    }));``

最佳答案

您似乎正在使用一个包含其他组件的组件。您必须添加您在 AppComponent 中使用的所有组件在 declarationconfigureTestingModule

关于angular6 - 非法状态 : Could not load the summary for directive AppComponent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52495262/

相关文章:

javascript - 动态地将一个组件追加到另一组件中

angular - RXJS6 升级 : ErrorObservable has no exported member 'ErrorObservable'

asp.net - Visual Studio 2017 Angular 6 显示 "Cannot Get/"仅限首次尝试

angular - 如何在vmware-clarity,Angular6中将sidenav导航链接的默认状态设置为关闭

angular6 - 修复 Internet Explorer 11 + Angular 6+ 项目中的语法错误

angular - typescript 错误 : TS2314: Generic type 'ElementRef<T, any>' requires 2 type argument(s)

html - Contenteditable div,获取表单值选项

Angular 6 自定义验证不允许空格作为第一个字符?

javascript - 是否有与 React Fragments 等效的 Angular 2+?

Angular 6 和 Bootstrap 4 可折叠 div 不起作用