components icon indicating copy to clipboard operation
components copied to clipboard

[Bug]: DatePicker isDateEnabled function sending InvalidDates as input during unit testing.

Open AkshayJangid opened this issue 1 year ago • 1 comments

Browser

Chrome

Package version

v3.0.501

React version

v18.0.01

Description

DatePicker-> isDateEnabled function while unit testing is sending "Invalid Date" as input. This is now happening for all dates, some dates do come up as fine. This is breaking unit tests. Input Date = Invalid Date. Error: Uncaught [TypeError: Cannot read properties of undefined (reading 'map')]

Source code

No response

Reproduction

datePickerComponent.findDatePicker().findOpenCalendarButton().click() This will trigger isDateEnabled function.

Code of Conduct

AkshayJangid avatar Jan 23 '24 12:01 AkshayJangid

Hello,

Could you please share a code snippet to show how the test is defined?

I tried the following:

test('isDateEnabled experiment', () => {
  const dates: string[] = [];
  const isDateEnabled = jest.fn().mockImplementation((date: Date) => {
    dates.push(date.toISOString());
    return true;
  });
  const { container } = render(<DatePicker {...defaultProps} isDateEnabled={isDateEnabled} />);

  createWrapper(container).findDatePicker()!.findOpenCalendarButton().click();
  console.log(dates);
});

The isDateEnabled is called for calendar dates and all of the dates are defined.

pan-kot avatar Jan 24 '24 10:01 pan-kot

Closing as the original question has been answered. Feel free to reopen if you have a follow-up ask

just-boris avatar Jan 29 '24 13:01 just-boris