Skip to content

Commit 50857a8

Browse files
authored
Merge pull request #56229 from callstack-internal/fix/unit-tests-for-CalendarPicker
[NOQA] fix unit tests for CalendarPicker
2 parents f4aef14 + 5bfc608 commit 50857a8

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

tests/unit/CalendarPickerTest.tsx

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type ReactNavigationNative from '@react-navigation/native';
2-
import {fireEvent, render, screen, within} from '@testing-library/react-native';
2+
import {fireEvent, render, screen, userEvent, within} from '@testing-library/react-native';
33
import {addMonths, addYears, subMonths, subYears} from 'date-fns';
44
import type {ComponentType} from 'react';
55
import CalendarPicker from '@components/DatePicker/CalendarPicker';
@@ -121,7 +121,7 @@ describe('CalendarPicker', () => {
121121
expect(onSelectedMock).toHaveBeenCalledWith('2022-02-15');
122122
});
123123

124-
test('should block the back arrow when there is no available dates in the previous month', () => {
124+
test('should block the back arrow when there is no available dates in the previous month', async () => {
125125
const minDate = new Date('2003-02-01');
126126
const value = new Date('2003-02-17');
127127

@@ -134,16 +134,17 @@ describe('CalendarPicker', () => {
134134
);
135135

136136
// When the previous month arrow is pressed
137-
fireEvent.press(screen.getByTestId('prev-month-arrow'));
137+
const user = userEvent.setup();
138+
await user.press(screen.getByTestId('prev-month-arrow'));
138139

139140
// Then the previous month should not be called as the previous month button is disabled
140-
const prevMonth = subMonths(new Date(), 1).getMonth();
141+
const prevMonth = subMonths(value, 1).getMonth();
141142
expect(screen.queryByText(monthNames.at(prevMonth) ?? '')).not.toBeOnTheScreen();
142143
});
143144

144-
test('should block the next arrow when there is no available dates in the next month', () => {
145+
test('should block the next arrow when there is no available dates in the next month', async () => {
145146
const maxDate = new Date('2003-02-24');
146-
const value = '2003-02-17';
147+
const value = new Date('2003-02-17');
147148
render(
148149
<CalendarPicker
149150
maxDate={maxDate}
@@ -152,10 +153,11 @@ describe('CalendarPicker', () => {
152153
);
153154

154155
// When the next month arrow is pressed
155-
fireEvent.press(screen.getByTestId('next-month-arrow'));
156+
const user = userEvent.setup();
157+
await user.press(screen.getByTestId('next-month-arrow'));
156158

157159
// Then the next month should not be called as the next month button is disabled
158-
const nextMonth = addMonths(new Date(), 1).getMonth();
160+
const nextMonth = addMonths(value, 1).getMonth();
159161
expect(screen.queryByText(monthNames.at(nextMonth) ?? '')).not.toBeOnTheScreen();
160162
});
161163

0 commit comments

Comments
 (0)