Skip to content

Commit ad15b7b

Browse files
Fix: Add test case for types
1 parent f5c0fe3 commit ad15b7b

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

components/date-picker/__tests__/type.test.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import * as React from 'react';
2+
import dayjs from 'dayjs';
3+
import type { Dayjs } from 'dayjs';
24

35
import DatePicker from '..';
46

@@ -58,4 +60,39 @@ describe('DatePicker.typescript', () => {
5860
const rangePicker = <DatePicker.RangePicker popupClassName="popupClassName" />;
5961
expect(rangePicker).toBeTruthy();
6062
});
63+
64+
it('DatePicker should accept only single value if multiple is false', () => {
65+
const mockSingleValue = dayjs();
66+
const mockOnChange = jest.fn<void, [Dayjs | null, string | null]>();
67+
const mockOnOk = jest.fn<void, [Dayjs | null]>();
68+
69+
const datePicker = (
70+
<DatePicker
71+
defaultValue={mockSingleValue}
72+
value={mockSingleValue}
73+
onChange={mockOnChange}
74+
onOk={mockOnOk}
75+
/>
76+
);
77+
78+
expect(datePicker).toBeTruthy();
79+
});
80+
81+
it('DatePicker should accept only array value if multiple is true', () => {
82+
const mockMultiValue = [dayjs()];
83+
const mockOnChange = jest.fn<void, [Dayjs[] | null, string[] | null]>();
84+
const mockOnOk = jest.fn<void, [Dayjs[] | null]>();
85+
86+
const datePicker = (
87+
<DatePicker
88+
multiple
89+
defaultValue={mockMultiValue}
90+
value={mockMultiValue}
91+
onChange={mockOnChange}
92+
onOk={mockOnOk}
93+
/>
94+
);
95+
96+
expect(datePicker).toBeTruthy();
97+
});
6198
});

0 commit comments

Comments
 (0)