From 6ff7b26cda34113a70a45f02c8b0db08b7c7bb05 Mon Sep 17 00:00:00 2001 From: balakrishna-deriv <56330681+balakrishna-deriv@users.noreply.github.com> Date: Mon, 1 Apr 2024 11:26:27 +0800 Subject: [PATCH] fix: moment test case (#14409) --- .../CompositeCalendar/__tests__/two-month-picker.spec.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/reports/src/Components/Form/CompositeCalendar/__tests__/two-month-picker.spec.tsx b/packages/reports/src/Components/Form/CompositeCalendar/__tests__/two-month-picker.spec.tsx index 3e6a7c906a97..2b091ab50839 100644 --- a/packages/reports/src/Components/Form/CompositeCalendar/__tests__/two-month-picker.spec.tsx +++ b/packages/reports/src/Components/Form/CompositeCalendar/__tests__/two-month-picker.spec.tsx @@ -22,9 +22,10 @@ describe('TwoMonthPicker', () => { }); it('should call onChange when a date is selected', () => { render(); - const prevMonthDate = screen.getAllByText(moment().format('D'))[0]; - const prevMonthFullDate = moment().subtract(2, 'month').format('YYYY-MM-DD'); - userEvent.click(prevMonthDate); + const prevMonthDate = moment().date(1).subtract(1, 'month'); + const prevMonthDateElement = screen.getAllByText(prevMonthDate.date())[0]; + const prevMonthFullDate = prevMonthDate.format('YYYY-MM-DD'); + userEvent.click(prevMonthDateElement); expect(mockProps.onChange).toHaveBeenCalledWith(moment.utc(prevMonthFullDate, 'YYYY-MM-DD')); }); it('should jump to current month from previous months upon clicking today button', () => {