2017-10-01 58 views
0

我使用ng2-bootstrap中的TooltipModule,最近切換到了ngx-bootstrap。工具提示在我的應用程序中工作正常 - 沒有問題。但是,在我的Angular組件測試中,當我導入以下內容:工具提示不適用於角度分量測試(來自ngx-bootstrap)

從'ngx-bootstrap'導入{TooltipModule};

,然後在測試牀,導入以下:

TestBed.configureTestingModule({ 進口:[TooltipModule.forRoot(),

工具提示不會呈現我沒有看到在開發者控制檯中的提示。 。在我的瀏覽器元素標籤 下當我使用NG2,引導進口爲:

進口{} TooltipModule從「NG2的自舉」;

一切正常鰭即我看到了呈現的工具提示。

這裏有什麼問題? Tooltip在我的應用程序中正常工作。只有在Angular測試中,我遇到了問題。爲了使工具提示能夠從ngx-bootstrap工作,我需要在測試中做不同或額外的工作嗎?

回答

0

這是我們做什麼(測試是真的老了,但仍然工作)

it('tooltip should be displayed by focus event after 0 ms by default', 
fakeAsync(() => { 
    const element: HTMLElement = fixture.debugElement.nativeElement; 
    const tooltipElement: any = element.querySelector('#test-tooltip1'); 
    tooltipElement.focus(); 
    fixture.detectChanges(); 
    tick(0); 
    fixture.detectChanges(); 
    expect(element.querySelector('.tooltip-inner')).not.toBeNull(); 
}) 
); 

全樣本可以在這裏找到:https://github.com/valor-software/ngx-bootstrap/blob/31c5f62a48560d4372f0043241829a27e5f3deb6/src/spec/tooltip.directive.spec.ts#L66-L77

0

你必須導入進口 { TooltipModule } from 'ngx-bootstrap';

在你的相關模塊如app.module不在你的組件中,然後在你的模塊導入數組中添加TooltipModule.forRoot()。您可以在app.modules組件中使用工具提示。

如果您使用的是延遲加載,然後將{ TooltipModule } from 'ngx-bootstrap';添加到其他模塊中。

相關問題