User-event: Error when using type on an element without a value property

Created on 21 Jul 2020  路  4Comments  路  Source: testing-library/user-event

  • @testing-library/user-event version: 12.0.11
  • Testing Framework and version: jest - 26.1.0
  • DOM Environment: react-dom - 16.13.1

Relevant code or config

import React from "react";
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";

describe("test", () => {
  it("does not throw on div type", async () => {
    render(<div tabIndex={0}>foo</div>);
    try {
      screen.getByText("foo").focus();
      await userEvent.type(screen.getByText("foo"), " ");
    } catch (e) {
      expect(e).toEqual("");
    }
  });
});

Reproduction repository:

https://codesandbox.io/s/agitated-meitner-3zhxf?file=/src/user-event.test.js

Problem description:

I assume that userEvent.type is the preferred way to simulate a keydown + keyup event on focused elements. If that is not the case, please consider this issue as irrelevant 馃槄

Using type on a element without value should not throw an error.

Suggested solution:

  • Don't throw an error when an element has no value property
  • Handle value mutation only if an element has a property value

Reminder: Add suggestions from https://github.com/testing-library/user-event/pull/409

accuracy help wanted released

Most helpful comment

Sure, I will 馃槃

All 4 comments

Hi @visualjerk,

I think the suggested solution is good. I'm worried about the challenges that contenteditable will present to us in the future, but if you just want to fire events at a div I think that's fine :)

@visualjerk Do you want to work on this PR 馃槂 ?

Sure, I will 馃槃

:tada: This issue has been resolved in version 12.0.14 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

Was this page helpful?
0 / 5 - 0 ratings