react-datepicker icon indicating copy to clipboard operation
react-datepicker copied to clipboard

Test using testing-library

Open 4r5i4 opened this issue 3 years ago • 1 comments

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

4r5i4 avatar May 18 '22 20:05 4r5i4

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.

github-actions[bot] avatar Jun 16 '24 01:06 github-actions[bot]

This issue was closed because it has been stalled for 10 days with no activity.

github-actions[bot] avatar May 03 '25 02:05 github-actions[bot]