Skip to content

Commit d8a47f2

Browse files
committed
test: Add tests for non-editable TextInput
1 parent 64bbde4 commit d8a47f2

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/__tests__/fireEvent.test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,46 @@ test('should not fire on disabled Pressable', () => {
193193
expect(handlePress).not.toHaveBeenCalled();
194194
});
195195

196+
test('should not fire on non-editable TextInput', () => {
197+
const placeholder = 'Test placeholder';
198+
const onChangeTextMock = jest.fn();
199+
const NEW_TEXT = 'New text';
200+
201+
const { getByPlaceholderText } = render(
202+
<View>
203+
<TextInput
204+
editable={false}
205+
placeholder={placeholder}
206+
onChangeText={onChangeTextMock}
207+
/>
208+
</View>
209+
);
210+
211+
fireEvent.changeText(getByPlaceholderText(placeholder), NEW_TEXT);
212+
expect(onChangeTextMock).not.toHaveBeenCalled();
213+
});
214+
215+
test('should not fire on non-editable TextInput with nested Text', () => {
216+
const placeholder = 'Test placeholder';
217+
const onChangeTextMock = jest.fn();
218+
const NEW_TEXT = 'New text';
219+
220+
const { getByPlaceholderText } = render(
221+
<View>
222+
<TextInput
223+
editable={false}
224+
placeholder={placeholder}
225+
onChangeText={onChangeTextMock}
226+
>
227+
<Text>Test text</Text>
228+
</TextInput>
229+
</View>
230+
);
231+
232+
fireEvent.changeText(getByPlaceholderText(placeholder), NEW_TEXT);
233+
expect(onChangeTextMock).not.toHaveBeenCalled();
234+
});
235+
196236
test('should pass event up on disabled TouchableOpacity', () => {
197237
const handleInnerPress = jest.fn();
198238
const handleOuterPress = jest.fn();

0 commit comments

Comments
 (0)