我想用 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[]>,以便我可以使用給定的負載呼叫此方法。
uj5u.com熱心網友回復:
您可以使用型別斷言將輸入引數轉換為您想要的任何值,例如:
const myEvent = {'foo': 'bar'} as CdkDragDrop<string[]>;
myComp.drop(myEvent);
這樣做,您的測驗應該可以編譯。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/370260.html
