Hacker0x01 / react-datepicker

A simple and reusable datepicker component for React
https://reactdatepicker.com/
MIT License
7.9k stars 2.23k forks source link

Test using testing-library #3631

Open 4r5i4 opened 2 years ago

4r5i4 commented 2 years ago

What I'm trying to achieve: test my component (which is simply a div wrapping around DatePicker to apply some styling) using testing-library

To Reproduce npm run test: fails with the following error:

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

What I have tried so far

  1. mocking the library:
    jest.mock('react-datepicker', () => ({
    default: () => {
    return <></>;
    },
    }));

Screenshots

component implementation

Screen Shot 2022-05-18 at 4 33 03 PM

test file

Screen Shot 2022-05-18 at 4 26 57 PM

terminal output

Screen Shot 2022-05-18 at 4 27 08 PM

github-actions[bot] commented 3 weeks ago

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 10 days.