2017-09-28 4 views
0

私はangular-cliプロジェクトを持っています。phantomjsによるカルマテストはngIfで失敗する

私がテストしたいHTMLは次のようになります。

<div *ngIf="!isMobile" class="shop-description"> 
    {{ description }} 
</div> 
<div class="shop-link"> 
    <span> 
    {{ link}} 
    </span> 
</div> 

テストは次のようになります。

beforeEach(() => { 
    fixture = TestBed.createComponent(ShopItemComponent); 
    component = fixture.componentInstance; 
    component.shop = ShopServiceMock.shops[0]; 
    component.isMobile = false; 
    fixture.detectChanges(); 
    }); 
    it('should have a title',() => { 
     fixture.detectChanges(); 
     const el = fixture.debugElement.nativeElement; 
     expect(el.querySelector('div.shop-title>span').innerText).toContain('test'); 
    }); 

    it('should have a description',() => { 
     fixture.detectChanges(); 
     const el = fixture.debugElement.nativeElement; 
     expect(el.querySelector('div.shop-description').innerText).toContain('love'); 
    }); 

コマンドすべてを渡す 'がNGテスト'、何の問題もなく。

TypeError: null is not an object (evaluating 'el.querySelector('div.shop-description').innerText')

答えて

関連する問題