Tôi đang sử dụng Chú giải công cụ và Mô-đun trong thành phần lồng nhau và trong tệp spec của tôi, tôi đang nhập NgbModule.forRoot()
trong mô-đun thử nghiệm.Sử dụng NgbModule.forRoot() trong thành phần khiến các kiểm tra thất bại
Điều này dường như làm việc ở khắp mọi nơi ngoại trừ trong một thành phần này, và nếu tôi thêm nhập khẩu này, nhiều đơn vị xét nghiệm của tôi đột nhiên bắt đầu thất bại với lỗi này:
TypeError: this._unregisterListenersFn is not a function
at NgbTooltip.ngOnDestroy
Tôi đang sử dụng góc CLI cho bundling/thử nghiệm.
Đây là thành phần duy nhất không thực hiện các thử nghiệm của tôi.
Tôi cũng đã cố gắng nhập riêng các mô-đun Tooltip/Modal và các nhà cung cấp có liên quan của riêng họ và tôi vẫn gặp phải lỗi ở trên. Nếu tôi thử nó mà không có forRoot()
, tôi nhận được lỗi DI.
Tôi không biết vấn đề là gì.
Dưới đây là file spec:
/* tslint:disable:no-unused-variable */
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { APP_BASE_HREF } from '@angular/common';
import { RouterTestingModule } from '@angular/router/testing';
import { NgbModule, NgbTooltipModule, NgbTooltipConfig, NgbModalModule } from '@ng-bootstrap/ng-bootstrap';
import { NgbModalStack } from '@ng-bootstrap/ng-bootstrap/modal/modal-stack';
import { ListItemComponent } from './list-item.component';
import { VideoPlayerService } from '../../../video-player';
import { CalendarRoutingService } from '../../calendar-routing.service';
describe('ListItemComponent',() => {
let component: ListItemComponent;
let fixture: ComponentFixture<ListItemComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
ListItemComponent
],
imports: [RouterTestingModule, NgbModule.forRoot()],
providers: [
VideoPlayerService,
CalendarRoutingService,
// NgbModalStack,
// NgbTooltipConfig
]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ListItemComponent);
component = fixture.componentInstance;
component.item = { records: [] };
fixture.detectChanges();
});
it('should create',() => {
expect(component).toBeTruthy();
});
});