2017-02-03 4 views
0

私はangle-cli(1.0.0-beta.26)を使用して作成された角度(2.4.5)のアプリケーションを持っており、テストの問題が発生しています。角度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]を使ってテストをパスすることができますが、それは正しいこととは思われません。

+0

コンソールからの完全な出力を教えてください。 –

+0

@MezoIstvan https://drive.google.com/file/d/0B5ymVhu1SZm0d3pPQUhOT3RhaEk/view?usp=sharing(ここに貼り付けるには大きすぎます)をご覧ください。 – sax

答えて

0

最後に、テストアイソレーションの問題は、一部のテストでdescribe()スコープ外に定義されたbeforeEach()関数によって引き起こされました。その結果、beforeEach()がスイート内のすべてのテストで実行され、上記の副作用が発生しました。