我正在做一些单元测试。
所以我有这个功能:
selectCluster(event: MouseEvent, feature: any) {
event.stopPropagation();
this.selectedCluster = {geometry: feature.geometry, properties: feature.properties};
}
和模板:
<mgl-popup *ngIf="selectedCluster" [feature]="selectedCluster">
</mgl-popup>
我有这样的测试:
fit('Should set selectedCluster when clicked', async(() => {
spyOn(component, 'selectCluster').and.callThrough();
fixture.detectChanges();
fixture.debugElement.query(By.css('.marker-cluster')).nativeElement.click();
tick();
fixture.whenStable().then(() => {
expect(component.selectCluster).toHaveBeenCalled();
});
}));
但我仍然收到此错误:
Cannot read property 'nativeElement' of null
那么我必须改变什么?
谢谢
这也使用了以下函数:
<ng-template mglClusterPoint let-feature>
<div class="marker-cluster" (click)="selectCluster($event, feature)">
<fa-icon [icon]="faVideo" [styles]="{'stroke': 'black', 'color': 'black'}" size="lg" class="pr-2"></fa-icon>
<fa-icon [icon]="faWifi" [styles]="{'stroke': 'black', 'color': 'black'}" size="lg" class="pr-2"></fa-icon>
</div>
</ng-template>
一只斗牛犬
相关分类