0
我有一个使用angular-cli(1.0.0-beta.26)创建的Angular(2.4.5)应用程序,我遇到了测试困难。我有一个简单的组件:Angular 2测试隔离(模板错误)
import { Component } from '@angular/core';
@Component({
selector: 'app-empty',
templateUrl: './empty.component.html',
styleUrls: ['./empty.component.css']
})
export class EmptyComponent { }
(两者的.html和.css是空文件)和单元测试:
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { EmptyComponent } from './empty.component';
describe('EmptyComponent',() => {
let component: EmptyComponent;
let fixture: ComponentFixture<EmptyComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ EmptyComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(EmptyComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create',() => {
expect(component).toBeTruthy();
});
});
当npm run test
启动测试失败,出现错误:
Uncaught Error: Template parse errors: Can't bind to 'value' since it
isn't a known property of 'app-detail-section-item'.
这涉及到一些其他正在测试的组件。我不明白为什么这个其他组件会影响EmptyComponent的测试?是否因为Webpack将测试捆绑在一起?我希望测试是孤立的。我可以使用schemas: [NO_ERRORS_SCHEMA]
进行测试,但这似乎不对。
你能给我们从控制台的全部输出吗? –
@MezoIstvan请在这里找到 - https://drive.google.com/file/d/0B5ymVhu1SZm0d3pPQUhOT3RhaEk/view?usp=sharing(这里粘贴太大了)。 – sax