【发布时间】:2022-01-06 21:18:54
【问题描述】:
我想用 angular+jest 对方法进行单元测试:
drop(event: CdkDragDrop<string[]>) {
if (event.previousContainer === event.container) {
moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
} else {
let clonedData: any = JSON.parse(JSON.stringify(event.item.data));
clonedData.paramId = this.IDGenerator() + '_' + event.currentIndex;
this.formCtrls.splice(event.currentIndex, 0, clonedData)
}
this.selectedControl = this.formCtrls[event.currentIndex];
}
是否可以为CdkDragDrop<string[]> 创建一个虚拟负载,以便我可以使用给定的负载调用此方法。
【问题讨论】:
-
你总是可以在你的测试中转换你的参数,例如
myComp.drop('foo' as CdkDragDrop<string[]>). -
@DonJuwe,您能否详细说明一下,如何做到这一点。感谢您的帮助