Angular 角度2测试隔离(模板错误)
我有一个使用Angular cli(1.0.0-beta.26)创建的Angular(2.4.5)应用程序,我遇到了测试困难。我有一个简单的组件:Angular 角度2测试隔离(模板错误),angular,testing,angular-cli,Angular,Testing,Angular Cli,我有一个使用Angular cli(1.0.0-beta.26)创建的Angular(2.4.5)应用程序,我遇到了测试困难。我有一个简单的组件: import { Component } from '@angular/core'; @Component({ selector: 'app-empty', templateUrl: './empty.component.html', styleUrls: ['./empty.component.css'] }) export clas
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();
});
});
这与其他一些也在测试中的部件有关。我不明白的是,为什么这个其他组件会影响EmptyComponent的测试?是因为Webpack将测试捆绑在一起吗?我希望测试是孤立的。我可以使用
模式通过测试:[NO_ERRORS\u SCHEMA]
,但这似乎不是正确的做法。最后,测试隔离问题是由beforeach()
函数在一些测试中定义的descripe()
范围之外引起的。这导致套件中的所有测试都运行了这些beforeach()
,我遇到了上面描述的副作用。您能给我们控制台的完整输出吗?@MezoIstvan请在这里找到它-(它太大了,无法粘贴在这里)。
Uncaught Error: Template parse errors: Can't bind to 'value' since it
isn't a known property of 'app-detail-section-item'.