FireEvent.change is not working for moment object


When I tried to change DatePicker input I am getting error.
Here is my components:

datePicker.js

  const DatePicker = ({ value, onChange, name, locale }) => {
      const myVal = value ? value.locale(locale) : '';
      return (
       <TextInput
         value={myVal}
         onChange={onChange}
         name={name}
       />)
  };
export default DatePicker;

date.js

import React from 'react';
import DatePicker from './datepicker';
const Date = () => { 
   const [dates, setDate] = useState('');
   return (
      <DatePicker
        name="date"
        value={dates}
        onChange={(_, value) => setDate(value)}
      />
 ); }

date.test.js

test('should render Date properly', () => {
const component = render(<Date />);

const date = component.container.querySelector(
  'input[name="date"]'
);
fireEvent.change(date, {
  target: {
    value: '10/1/2021',
  },
});

});

Here is the error which I am getting:

 TypeError: value.locale is not a function
 fireEvent.change(adjustmentDate, {
           ^
     target: {
        value: '10/1/2021',
     },

Source: React – Stack Overflow

October 30, 2021
Category : News
Tags: momentjs | react-testing-library | reactjs | testing | unit testing

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.