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..fb3c7a59 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, element.maxLength > 0 ? element.maxLength : text.length); + } else { + computedText = text.slice(0, element.maxLength); + } const previousText = element.value;