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