I am facing an issue with a component that utilizes the DateTimePicker
tool from the react-native-ui-datepicker
library. When I try to write a test case for it using jest
, an error is being displayed:
Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object.
Check the render method of `SingleDatePicker`.
at onChange (/Users/**/DateTimePicker/SingleDatePicker.tsx:9:3)
18 | testID="single-date-picker"
19 | >
> 20 | <DateTimePicker
| ^
21 | mode={'single'}
22 | date={date}
23 | onChange={onChange}
at printWarning (node_modules/react/cjs/react-jsx-runtime.development.js:87:30)
at error (node_modules/react/cjs/react-jsx-runtime.development.js:61:7)
The test case in question is as follows:
import React from 'react';
import dayjs from 'dayjs';
import { render } from '@testing-library/react-native';
import DatePicker from './DatePicker';
import { screen } from '@testing-library/react-native';
jest.mock('react-native-ui-datepicker', () => ({
default: jest.fn(),
}));
const mockOnChange = jest.fn();
describe('Testing DatePicker', () => {
const date = dayjs().format();
it('Testing DatePicker', () => {
render(
<DatePicker type="single" date={date} onChange={mockOnChange} />
);
expect(screen.queryByTestId('single-date-picker')).toBeTruthy();
});
});
Can anyone provide insights on how to resolve this error?