Closed
Description
As mentioned in title changing selectionStart
has no effect when using userEvent.type(input, "foobar")
, eg:
test("selectionStart is not used when updating input", async () => {
const { getByTestId } = render(<App />);
await waitForElement(() => getByTestId("testinput"));
const input = getByTestId("testinput");
expect(input).not.toBeNull();
expect(input.value).toBe("xyz");
// move cursor to the beginning of input
input.focus();
input.setSelectionRange(0, 0);
expect(input.selectionStart).toBe(0);
expect(input.selectionEnd).toBe(0);
// start typing
await userEvent.type(input, "abc");
expect(input.value).toBe("abcxyz"); // <-- FAILS
expect(input.selectionStart).toBe(3);
});
Important: in the test case I use react-scripts test --env=jsdom-sixteen
as jsdom
had fixed selectionStart
only recently jsdom/jsdom#2787
Metadata
Metadata
Assignees
Labels
No labels