我正在运行Angular2测试教程。我对Jasmine/Karma很新,所以这可能是一些基本的东西。我发现,一旦我有“故宫测试”运行,如果我做出改变,测试运行尝试重装,但得到的错误:Angular2 Karma test runner not reloading
ERROR in C:/dev/unittest1/src/app/banner-inline/banner-inline.component.spec.ts (12,11): Cannot find name 'HTMLElement'.)
这里是规格代码(非常简单,只是从拍摄here):
从'@ angular/core/testing'导入{ComponentFixture,TestBed,ComponentFixtureAutoDetect}; 从'@ angular/platform-browser'导入{By}; 从'@ angular/core'导入{DebugElement};
import { BannerInlineComponent } from './banner-inline.component';
describe('BannerInlineComponent (inline template)',() => {
let comp: BannerInlineComponent;
let fixture: ComponentFixture<BannerInlineComponent>;
let de: DebugElement;
let el: HTMLElement;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [BannerInlineComponent], // declare the test component
providers: [{ provide: ComponentFixtureAutoDetect, useValue: true }]
});
fixture = TestBed.createComponent(BannerInlineComponent);
comp = fixture.componentInstance; // BannerInlineComponent test instance
// query for the title <h1> by CSS element selector
de = fixture.debugElement.query(By.css('h1'));
el = de.nativeElement;
});
it('should display original title',() => {
expect(el.textContent).toContain(comp.title);
});
it('should still see original title after comp.title change',() => {
const oldTitle = comp.title;
comp.title = 'Test Title';
fixture.detectChanges();
// Displayed title is old because Angular didn't hear the change :(
expect(el.textContent).toContain(oldTitle);
});
it('should display updated title after detectChanges',() => {
comp.title = 'Test Title';
fixture.detectChanges(); // detect changes explicitly
expect(el.textContent).toContain(comp.title);
});
});
如果我停止测试运行并重新启动它,一切工作正常。为什么我得到这个错误,我该如何防止它?
你能请张贴规范文件,错误就自我指定它状态并没有能够鳍片规范文件中被称为HTML元素的必需属性,它可能基于某些触发器进行配置,需要查看spec文件 –
我已经添加了规范代码。请记住,在“npm test”重新开始时找到它并没有什么问题。 –