React-testing-library: Unable to test antd 3.x Datepicker

Created on 12 Nov 2020  路  2Comments  路  Source: testing-library/react-testing-library

  • @testing-library/react version: 11.1.0
  • Testing Framework and version: Jest
  • DOM Environment: @testing-library/jest-dom 5.11.5

Relevant code or config:

    const datePicker = getByTestId("date-picker");
    fireEvent.click(datePicker);
    console.log(datePicker);
    fireEvent.change(datePicker, { target: { value: "29 Oct, 2020" } });
    expect(datePicker.value).toBe("29 Oct, 2020");

What you did:

I trying to

  • Click on the Datepicker component
  • Change its value
  • expecting the changed date in the value

What happened:

Screenshot 2020-11-12 at 12 23 51 PM

Reproduction:

https://codesandbox.io/s/datepicker-test-forked-c1jjp?file=/src/index.test.js

Problem description:

The value of the date picker component wasn't changed

question

Most helpful comment

This seems to be a bug with antd 3 (see original issue solution). antd 4 has already fixed this using the same React Testing Library code, and if <input type="date" /> is used instead it still works (though you'd have to use a different format).

I don't think we should support a workaround for a bug in another library that's already been patched unless React Testing Library is doing something incorrectly. If you can show proof of React Testing Library doing something incorrectly with a date input that isn't based on antd we may be able to help.

Otherwise, you have some alternative options:

  1. Migrate to antd 4
  2. Patch antd 3 to fix this bug yourself, as it's not going to be implemented upstream
  3. Use yarn 2 resolutions to install both versions of antd and only use DatePicker from 4
  4. Reimplement your own DatePicker based on antd 4's implementation
  5. Use a standard input (like my example) or another date picker library
  6. Figure out a workaround in your test that avoids the bugs in antd 3's implementation

All 2 comments

This seems to be a bug with antd 3 (see original issue solution). antd 4 has already fixed this using the same React Testing Library code, and if <input type="date" /> is used instead it still works (though you'd have to use a different format).

I don't think we should support a workaround for a bug in another library that's already been patched unless React Testing Library is doing something incorrectly. If you can show proof of React Testing Library doing something incorrectly with a date input that isn't based on antd we may be able to help.

Otherwise, you have some alternative options:

  1. Migrate to antd 4
  2. Patch antd 3 to fix this bug yourself, as it's not going to be implemented upstream
  3. Use yarn 2 resolutions to install both versions of antd and only use DatePicker from 4
  4. Reimplement your own DatePicker based on antd 4's implementation
  5. Use a standard input (like my example) or another date picker library
  6. Figure out a workaround in your test that avoids the bugs in antd 3's implementation

Got it.
Thanks @nickmccurdy

Was this page helpful?
0 / 5 - 0 ratings