Jest tests failing with error TypeError _moment.default.localeData is not a function
See original GitHub issuereact-dates version e.g. react-dates@18.3.1
Describe the bug
I’ve set up a jest test to render my component that is using a react-dates datepicker, and I’ve
imported 'react-dates/initialize'
, but my test fails with the error:
TypeError: _moment.default.localeData is not a function
Source code (including props configuration) Steps to reproduce the behavior:
<DateRangePicker
startDate={this.state.startDate}
startDateId="your_unique_start_date_id"
endDate={this.state.endDate}
endDateId="your_unique_end_date_id"
onDatesChange={({ startDate, endDate }) => this.setState({ startDate, endDate })}
focusedInput={this.state.focusedInput}
onFocusChange={focusedInput => this.setState({ focusedInput })}
/>
If you have custom methods that you are passing into a react-dates
component, e.g. onDatesChange
, onFocusChange
, renderMonth
, isDayBlocked
, etc., please include the source for those as well.
Screenshots/Gifs If applicable, add screenshots or gifs to help explain your problem.
Desktop (please complete the following information):
- OS: [e.g. iOS] Mac OS 10.13.6
- Browser [e.g. chrome, safari] Chrome
- Version [e.g. 22] 72.0.3626.121 (Official Build) (64-bit)
Smartphone (please complete the following information):
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
Is the issue reproducible in Storybook? The issue is not reproducible in storybook. This only happens in test.
Additional context Add any other context about the problem here.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
Hi @ljharb ! I managed to get it to work. My mock looked like this:
I changed it into
😃
Closing, but will be happy to reopen if @mkelley33 can reply with clarification.