Home > Net >  Create dummy payload for CdkDragDrop event
Create dummy payload for CdkDragDrop event

Time:12-01

I want to unit test a method, in 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];
  }

Is it possible to create a dummy payload for CdkDragDrop<string[]>, so that i can call this method with given payload.

CodePudding user response:

You can use Type Assertions to cast your input parameter to whatever you want it to be, e.g.:

const myEvent = {'foo': 'bar'} as CdkDragDrop<string[]>;
myComp.drop(myEvent);

Doing so, your test should compile.

  • Related