我有一个看起来像这样的组件:
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() {
}
}
在我的业力,规范中,我有以下内容:
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浏览器中的错误如下:
错误:非法状态:无法加载指令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
答案 0 :(得分:1)
@ Atticus29通常会在您错过时出现此错误:
尝试检查任何引用的组件或模块。