2
votes

I have a function which needs date from datepicker event. I used matdatepicker to select date from UI.

i want to pass date event value on onDateSelected() function.

can anybody help me to pass date event value to pass my unit test case.

i tried below code but it wont works

my function

 onDateSelected(event: MatDatepickerInputEvent<Date>) {
    const dts = event.value;
    const startDate = moment(dts).format('MM/DD/YYYY');
    this.details.controls.contractStartDate.setValue(startDate);
    this.selectedDate = this.details.get('contractStartDate').value;
    this.selectedDate = event.value;
  }

Unit testing code

  it('should check ondate selected event', () => {
    const date = new Date(10/03/2019);
    component.onDateSelected(date);
    fixture.detectChanges();
    expect(component.details.get('contractStartDate').value.toString()).toEqual(date);
  });
1

1 Answers

3
votes
const date: any = { value : new Date(10/03/2019) };

Just look at how you write your function, and follow the object properties.