-
Notifications
You must be signed in to change notification settings - Fork 273
Support "editable" on TextInput #476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @thymikee, I'd like to tackle this one. |
@pitpitpat go for it! |
I'm using version 11.0.0. const handleFocus = jest.fn();
const result = render(
<TextInput
testID="my-input"
onFocus={handleFocus}
editable={false}
/>,
);
const rnTextInput = result.getByTestId('my-input');
act(() => {
fireEvent(rnTextInput, 'focus');
// or fireEvent(rnTextInput, 'click');
// or fireEvent.press(rnTextInput);
});
expect(handleFocus).not.toBeCalled(); Result: |
@douglasjunior we have 2 tests for this scenario which are passing on our infra. Mind investigating on your side, reducing it to a minimal setup and see if some 3rd-party code doesn't interfere? Btw, there's no need to wrap |
Hi @thymikee, thank you for the quick response! I've just tested on a new project here. Create a new RN 0.68.2 project using TypeScript template:
Add testing-library:
Edit the it('test TextInput native', () => {
const handleFocus = jest.fn();
const result = render(
<TextInput testID="my-input" onFocus={handleFocus} editable={false} />,
);
const rnTextInput = result.getByTestId('my-input');
fireEvent(rnTextInput, 'focus');
expect(handleFocus).not.toBeCalled();
}); Run tests:
Sample project: https://github.com/douglasjunior/TestingLibrarySample Other people with similar problem: https://stackoverflow.com/q/65625330/2826279 Thanks! |
Would you be able to create a PR with this test failing? |
Sure. I think I figured out the problem, if using "placeholder" instead of "testID" works as expected. it('test TextInput native by placeholder', () => {
const handleFocus = jest.fn();
const result = render(
<TextInput
placeholder="my-input"
onFocus={handleFocus}
editable={false}
/>,
);
const rnTextInput = result.getByPlaceholderText('my-input');
fireEvent(rnTextInput, 'focus');
expect(handleFocus).not.toBeCalled(); // <--- pass
});
it('test TextInput native by testID', () => {
const handleFocus = jest.fn();
const result = render(
<TextInput testID="my-input" onFocus={handleFocus} editable={false} />,
);
const rnTextInput = result.getByTestId('my-input');
fireEvent(rnTextInput, 'focus');
expect(handleFocus).not.toBeCalled(); // <--- fail
}); |
Thanks! Looking forward to the PR :) |
Done #1080 |
Another scenario that's don't work as expected is when wrapping with it('test TextInput native by custom component', () => {
const CustomTextInput: React.FC<{ theme: AppThemeType } & TextInputProps> = props => <TextInput testID="rn-text-input" {...props} />;
const CustomInputWithTheme = withTheme(CustomTextInput);
const handleFocus = jest.fn();
const result = render(
<CustomInputWithTheme
placeholder="my-input"
onFocus={handleFocus}
editable={false}
/>,
);
const rnTextInput = result.getByPlaceholderText('my-input');
fireEvent(rnTextInput, 'focus');
expect(handleFocus).not.toBeCalled(); // <--- fail
}); |
Describe the Feature
TextInput
component fromreact-native
has its own handling of being disabled/editable. It's not using responder system like Views, Texts and thus Touchables, so the logic we have already fails to catch it.We should consider adding custom handling specific to native TextInput component, since it was working with
@testing-library/react-native
before v7.Possible Implementations
Will likely involve detecting
TextInput
and verify if it's editable or not.Test that fails with current implementation:
The text was updated successfully, but these errors were encountered: