From 487c43a56b6f44402eda231a3c79f106832e67a3 Mon Sep 17 00:00:00 2001 From: Thomas Roest Date: Wed, 25 Mar 2020 09:20:26 +0100 Subject: [PATCH 1/2] ignore maxLength -1 for userEvent.type --- __tests__/react/type.js | 9 +++++++++ src/index.js | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/__tests__/react/type.js b/__tests__/react/type.js index ca804e9b..283d518e 100644 --- a/__tests__/react/type.js +++ b/__tests__/react/type.js @@ -208,4 +208,13 @@ describe("userEvent.type", () => { expect(onKeyUp).not.toHaveBeenCalled(); } ); + + it("should ignore maxLength with value -1", () => { + const { getByTestId } = render( + + ); + const input = getByTestId("input"); + userEvent.type(input, "test"); + expect(input).toHaveProperty("value", "test"); + }); }); diff --git a/src/index.js b/src/index.js index 075e3edb..f82a749c 100644 --- a/src/index.js +++ b/src/index.js @@ -183,7 +183,12 @@ const userEvent = { }; const opts = Object.assign(defaultOpts, userOpts); - const computedText = text.slice(0, element.maxLength || text.length); + let computedText; + if (!element.maxLength || element.maxLength === -1) { + computedText = text.slice(0, text.length); + } else { + computedText = text.slice(0, element.maxLength); + } const previousText = element.value; From 624ee817ccee36c1370113aba9737a67f0bfbcad Mon Sep 17 00:00:00 2001 From: Thomas Roest Date: Mon, 30 Mar 2020 18:23:57 +0200 Subject: [PATCH 2/2] Update src/index.js Co-Authored-By: Adam Palaniuk --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index f82a749c..fb3c7a59 100644 --- a/src/index.js +++ b/src/index.js @@ -185,7 +185,7 @@ const userEvent = { let computedText; if (!element.maxLength || element.maxLength === -1) { - computedText = text.slice(0, text.length); + computedText = text.slice(0, element.maxLength > 0 ? element.maxLength : text.length); } else { computedText = text.slice(0, element.maxLength); }