I've got these 2 Unit tests for the Angular Material DatePicker in Angular. I can't understand why the result I get is 1 vs. expected 31... describe('startTimeChange', () => { test('should emit updated input start date range with time', () => { component.ngOnInit(); jest.spyOn(component, 'dateRangeChanged'); // any = MatDatepickerInputEvent<Date> const updatedDateTime: any = { value: new DateRange<moment.Moment>(moment(), component.dateRange.end) } component.startTimeChange(updatedDateTime); expect(component.selectedDateRangeOption).toBe(DateRangeOption.Custom); expect(component.dateRange.start?.date()).toEqual(moment(updatedDateTime.value).date()); // Here's where it fails expect(component.dateRange.end).toEqual(component.dateRange.end); expect(component.dateRangeChange.emit).toHaveBeenCalledWith(component.dateRange); expect(component.dateRangeChanged).toHaveBeenCalledTimes(1); }); }); describe('endTimeChange', () => { test('should emit updated input end date range with time', () => { component.ngOnInit(); jest.spyOn(component, 'dateRangeChanged'); // any = MatDatepickerInputEvent<Date> const updatedDateTime: any = { value: new DateRange<moment.Moment>(component.dateRange.end, moment()) } component.endTimeChange(updatedDateTime); expect(component.selectedDateRangeOption).toBe(DateRangeOption.Custom); expect(component.dateRange.start).toEqual(component.dateRange.start); expect(component.dateRange.end?.date()).toEqual(moment(updatedDateTime.value).date()); // Here's where it fails expect(component.dateRangeChange.emit).toHaveBeenCalledWith(component.dateRange); expect(component.dateRangeChanged).toHaveBeenCalledTimes(1); }); }); Continue reading...