Skip to content

Commit

Permalink
test(type): can't write past maxLength
Browse files Browse the repository at this point in the history
  • Loading branch information
klujanrosas committed Nov 19, 2019
1 parent 7e31a51 commit 61a1b6d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
25 changes: 25 additions & 0 deletions __tests__/react/type.js
Expand Up @@ -135,4 +135,29 @@ describe("userEvent.type", () => {
expect(getByTestId("input")).toHaveProperty("value", text);
}
);

it.each(["input", "textarea"])(
"should type text in <%s> up to maxLength if provided",
type => {
const onChange = jest.fn();
const maxLength = 10;

const { getByTestId } = render(
React.createElement(type, {
"data-testid": "input",
onChange: onChange,
maxLength
})
);

const text = "superlongtext";
const slicedText = text.slice(0, maxLength);

userEvent.type(getByTestId("input"), text, {
allAtOnce: true
});

expect(getByTestId("input")).toHaveProperty("value", slicedText);
}
);
});
19 changes: 19 additions & 0 deletions __tests__/vue/type.js
Expand Up @@ -145,4 +145,23 @@ describe("userEvent.type", () => {
expect(input).toHaveBeenCalledTimes(1);
}
);

it.each(["input", "textarea"])(
"should type text in <%s> up to maxLength if provided",
type => {
const input = jest.fn();
const maxLength = 10;

const { getByTestId } = renderComponent(type, { input }, { maxLength });

const text = "superlongtext";
const slicedText = text.slice(0, maxLength);

userEvent.type(getByTestId("input"), text, {
allAtOnce: true
});

expect(getByTestId("input")).toHaveProperty("value", slicedText);
}
);
});

0 comments on commit 61a1b6d

Please sign in to comment.