-
Notifications
You must be signed in to change notification settings - Fork 277
Closed
Description
Describe the bug
It is possible to change the value of a TextInput that has a maxLength prop. The following test fails for instance :
test('it should not allow to write a text longer than maxlength in a text input', () => {
const TestComponent = () => {
const [value, setValue] = useState('');
return (
<RNTextInput placeholder="placeholder" maxLength={1} onChangeText={setValue} value={value} />
);
};
render(<TestComponent />);
fireEvent.changeText(screen.getByPlaceholderText('placeholder'), 'text');
screen.debug();
expect(screen.queryByDisplayValue('text')).toBeFalsy();
});
Expected behavior
I'd expect that only the substring of length equal to maxlength is set as value.
Regarding the implementation I'm not sure though if this should be done by fireEvent because it just calls props and we'd have to check what the event is and have special checks in that case so maybe it's something that should be done once we have an implementation of userEvent.type. So actually I'm saying this is not really a bug but rather a use case that userEvent.type should support
Metadata
Metadata
Assignees
Labels
No labels