我有一个看起来像这样的组件:
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 通常在您错过以下操作时会出现此错误:
- 声明一些相关组件
- 在导入中添加一些引用的模块
尝试检查任何引用的组件或模块。
关于javascript - Angular2 + karma 测试 : “Illegal state: Could not load the summary for directive Foo.” ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47603526/