angular - 如何解决Cannot read property 'triggerEventHandler' of null in angular jest
问题描述
我有HTML
一个自定义元素的代码:
<md-tab-content>
<md-tab-pane *ngFor="let tab of tabSequence" class="md-margin__vertical--l" [ngClass]="{'md-padding__vertical--xl': !dataLoaded}">
<ng-template [ngIf]="dataLoaded" [ngIfElse]="loading">
<ng-template [ngIf]="hasIssues && activeTab == tab && chartData[tab]" [ngIfElse]="noIssues">
<webex-chartjs-donut-chart
class="md-padding__horizontal--none"
[data]="chartData[tab]"
[plugins]="plugins"
[legendTemplate]="legendTemplate"
[config]="{ legendDirection: 'vertical', preventDefaultLegendClick: true }"
(legendClick)="legendClicked($event)"
></webex-chartjs-donut-chart>
</ng-template>
</ng-template>
</md-tab-pane>
</md-tab-content>
而且,我想模拟这个legenClicked
功能。所以,我写了这个测试:
it('should call legendClick function', () => {
enum TABS {
SYSTEM,
VOICE_VIDEO,
IMnP,
CUSTOM,
UnityConnection
}
component.dataLoaded = true;
component.hasIssues = true;
component.activeTab = TABS.CUSTOM;
component.chartData = TABS.CUSTOM ;
const donut = fixture.debugElement.query(By.css('webex-chartjs-donut-chart'));
donut.triggerEventHandler('legendClick', {});
fixture.detectChanges();
expect(component.legendClicked).toHaveBeenCalled()
})
但是,我得到这个错误:
TypeError: Cannot read property 'triggerEventHandler' of null
我该如何进行?提前致谢。
解决方案
推荐阅读
- android - Android Studio SDK 未显示对 Android 7.1.2 的支持?
- vb.net - 创建动态 DataGridViewComboBoxCells
- python - 使用 Numpy 迭代 DataFrame 行以创建新列
- python - 使用 Python 从 aspx 页面下载 .xls 文件
- node.js - UnhandledPromiseRejectionWarning:nodejs服务器中未处理的承诺拒绝
- r - Rscript在容器中找不到已安装的软件包
- java - 如何将 RESTful 服务器与 Apache Kafka 结合起来?
- angular - 访问指令中的属性
- angular - Angular LazyLoad 模块调用奇怪的组件
- infinispan - jgroup GOOGLE_PING 成员未删除