From a44b14a07478343933e3beca5bfa0bf16f3938d4 Mon Sep 17 00:00:00 2001 From: "Kent C. Dodds" Date: Mon, 8 Jun 2020 12:06:38 -0600 Subject: [PATCH] fix(type): ensure the selectionStart/End are consistent with browsers (#322) Closes: #321 Closes: #318 Closes: #316 --- src/__tests__/type-modifiers.js | 8 +++++ src/__tests__/type.js | 50 ++++++++++++++++++++++++++ src/type.js | 64 +++++++++++++++++++++++++-------- typings/index.d.ts | 6 ++-- 4 files changed, 112 insertions(+), 16 deletions(-) diff --git a/src/__tests__/type-modifiers.js b/src/__tests__/type-modifiers.js index f398ea99..be1b3dee 100644 --- a/src/__tests__/type-modifiers.js +++ b/src/__tests__/type-modifiers.js @@ -117,6 +117,14 @@ test('{backspace} deletes the selected range', async () => { `) }) +test('{backspace} on an input type that does not support selection ranges', async () => { + const {element} = setup() + // note: you cannot even call setSelectionRange on these kinds of elements... + await userEvent.type(element, '{backspace}') + // removed "m" + expect(element).toHaveValue('yo@example.co') +}) + test('{alt}a{/alt}', async () => { const {element: input, getEventCalls} = setup() diff --git a/src/__tests__/type.js b/src/__tests__/type.js index 8735dfee..8b57efe5 100644 --- a/src/__tests__/type.js +++ b/src/__tests__/type.js @@ -521,3 +521,53 @@ test('ignored {backspace} in controlled input', async () => { keyup: 4 (52) `) }) + +// https://github.com/testing-library/user-event/issues/321 +test('typing in a textarea with existing text', async () => { + const {element, getEventCalls} = setup(