gpt4 book ai didi

javascript - Angular2 + karma 测试 : “Illegal state: Could not load the summary for directive Foo.”

转载 作者:太空狗 更新时间:2023-10-29 19:27:35 25 4
gpt4 key购买 nike

我有一个看起来像这样的组件:

import { Component, OnInit } from '@angular/core';

@Component({
selector: 'app-youtube',
templateUrl: './youtube.component.html',
styleUrls: ['./youtube.component.css']
})
export class YoutubeComponent implements OnInit {

constructor() { }

ngOnInit() {
}

}

在我的 karma 规范中,我有以下内容:

import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { YoutubeComponent } from './youtube.component';

describe('YoutubeComponent', () => {
let component: YoutubeComponent;
let fixture: ComponentFixture<YoutubeComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
// providers: [YoutubeComponent],tried this, and it makes no difference
declarations: [ YoutubeComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(YoutubeComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});

我在 Karma 浏览器中遇到的错误如下所示:

Error: Illegal state: Could not load the summary for directive YouTubeComponent.

似乎previous, related questions通过添加行 declarations: [ YoutubeComponent ] 来解决,我已经有了。还有其他建议吗?

github 上有一个可重现的例子:

git clone https://github.com/Atticus29/dataJitsu.git
cd dataJitsu
git checkout modalSO
rm package-lock.json
npm install
npm test

最佳答案

@Atticus29 通常在您错过以下操作时会出现此错误:

  1. 声明一些相关组件
  2. 在导入中添加一些引用的模块

尝试检查任何引用的组件或模块。

关于javascript - Angular2 + karma 测试 : “Illegal state: Could not load the summary for directive Foo.” ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47603526/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com