我需要在 Angular 中测试一个只有一种方法和某些 @Input 和 @Output 属性的组件-
updateColumns(eventValue: ManagedColumns) {
this.applyColumnChanges.emit(eventValue);
}
还有另一个组件具有应该调用上述方法的方法。调用,因为它正在发出一个事件,该事件将被另一个我相信的事件消耗,而该事件又会发出另一个事件,该事件被另一个组件中的第三个事件消耗 -
applyChanges() {
this.apply.emit(<ManagedColumns>{
selectedColumns: this.selectedItems.slice(),
availableColumns: this.availableItems.slice()
});
this.closeDialog();
}
我正在尝试测试 updateColumns 但不知怎么做?是否可以模拟 applyChanges 依次发送到 updateColumns 并且我们可以检查相同的值?
如果我尝试 -
manageColumnsComponent = TestBed.createComponent(ManageColumnsComponent).componentInstance;
spyOn(manageColumnsComponent.applyChanges, 'emit');
得到错误 -
[ts] Argument of type '"emit"' is not assignable to parameter of type 'never'.