Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f0df299

Browse files
authoredAug 13, 2024··
feat: remove 'textInput' event from UserEvent type() (#1645)
1 parent 430213f commit f0df299

File tree

8 files changed

+6
-116
lines changed

8 files changed

+6
-116
lines changed
 

‎src/user-event/__tests__/__snapshots__/clear.test.tsx.snap

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -331,30 +331,6 @@ How are you?" multiline: true, 1`] = `
331331
"timeStamp": 0,
332332
},
333333
},
334-
{
335-
"name": "textInput",
336-
"payload": {
337-
"currentTarget": {},
338-
"isDefaultPrevented": [Function],
339-
"isPersistent": [Function],
340-
"isPropagationStopped": [Function],
341-
"nativeEvent": {
342-
"previousText": "Hello World!
343-
How are you?",
344-
"range": {
345-
"end": 0,
346-
"start": 0,
347-
},
348-
"target": 0,
349-
"text": "",
350-
},
351-
"persist": [Function],
352-
"preventDefault": [Function],
353-
"stopPropagation": [Function],
354-
"target": {},
355-
"timeStamp": 0,
356-
},
357-
},
358334
{
359335
"name": "change",
360336
"payload": {

‎src/user-event/__tests__/clear.test.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ function renderTextInputWithToolkit(props: TextInputProps = {}) {
2020
onChange={logEvent('change')}
2121
onChangeText={logEvent('changeText')}
2222
onKeyPress={logEvent('keyPress')}
23-
/** @ts-expect-error property typedef removed in RN 0.75 */
24-
onTextInput={logEvent('textInput')}
2523
onSelectionChange={logEvent('selectionChange')}
2624
onSubmitEditing={logEvent('submitEditing')}
2725
onEndEditing={logEvent('endEditing')}
@@ -142,7 +140,6 @@ describe('clear()', () => {
142140
'focus',
143141
'selectionChange',
144142
'keyPress',
145-
'textInput',
146143
'change',
147144
'changeText',
148145
'selectionChange',

‎src/user-event/clear.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,23 @@ export async function clear(this: UserEventInstance, element: ReactTestInstance)
2424
dispatchEvent(element, 'focus', EventBuilder.Common.focus());
2525

2626
// 2. Select all
27-
const previousText = element.props.value ?? element.props.defaultValue ?? '';
27+
const textToClear = element.props.value ?? element.props.defaultValue ?? '';
2828
const selectionRange = {
2929
start: 0,
30-
end: previousText.length,
30+
end: textToClear.length,
3131
};
3232
dispatchEvent(element, 'selectionChange', EventBuilder.TextInput.selectionChange(selectionRange));
3333

3434
// 3. Press backspace with selected text
35-
const finalText = '';
35+
const emptyText = '';
3636
await emitTypingEvents(element, {
3737
config: this.config,
3838
key: 'Backspace',
39-
text: finalText,
40-
previousText,
39+
text: emptyText,
4140
});
4241

4342
// 4. Exit element
4443
await wait(this.config);
45-
dispatchEvent(element, 'endEditing', EventBuilder.TextInput.endEditing(finalText));
46-
44+
dispatchEvent(element, 'endEditing', EventBuilder.TextInput.endEditing(emptyText));
4745
dispatchEvent(element, 'blur', EventBuilder.Common.blur());
4846
}

‎src/user-event/event-builder/text-input.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,6 @@ export const TextInputEventBuilder = {
6363
};
6464
},
6565

66-
/**
67-
* Experimental values:
68-
* - iOS: `{"eventCount": 2, "previousText": "Te", "range": {"end": 2, "start": 2}, "target": 75, "text": "s"}`
69-
* - Android: `{"previousText": "Te", "range": {"end": 2, "start": 0}, "target": 53, "text": "Tes"}`
70-
*/
71-
textInput: (text: string, previousText: string) => {
72-
return {
73-
...baseSyntheticEvent(),
74-
nativeEvent: {
75-
text,
76-
previousText,
77-
range: { start: text.length, end: text.length },
78-
target: 0,
79-
},
80-
};
81-
},
82-
8366
/**
8467
* Experimental values:
8568
* - iOS: `{"contentSize": {"height": 21.666666666666668, "width": 11.666666666666666}, "target": 75}`

‎src/user-event/type/__tests__/__snapshots__/type.test.tsx.snap

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -843,30 +843,6 @@ exports[`type() supports multiline: input: "{Enter}\\n", multiline: true 1`] = `
843843
"timeStamp": 0,
844844
},
845845
},
846-
{
847-
"name": "textInput",
848-
"payload": {
849-
"currentTarget": {},
850-
"isDefaultPrevented": [Function],
851-
"isPersistent": [Function],
852-
"isPropagationStopped": [Function],
853-
"nativeEvent": {
854-
"previousText": "",
855-
"range": {
856-
"end": 1,
857-
"start": 1,
858-
},
859-
"target": 0,
860-
"text": "
861-
",
862-
},
863-
"persist": [Function],
864-
"preventDefault": [Function],
865-
"stopPropagation": [Function],
866-
"target": {},
867-
"timeStamp": 0,
868-
},
869-
},
870846
{
871847
"name": "change",
872848
"payload": {
@@ -950,32 +926,6 @@ exports[`type() supports multiline: input: "{Enter}\\n", multiline: true 1`] = `
950926
"timeStamp": 0,
951927
},
952928
},
953-
{
954-
"name": "textInput",
955-
"payload": {
956-
"currentTarget": {},
957-
"isDefaultPrevented": [Function],
958-
"isPersistent": [Function],
959-
"isPropagationStopped": [Function],
960-
"nativeEvent": {
961-
"previousText": "
962-
",
963-
"range": {
964-
"end": 2,
965-
"start": 2,
966-
},
967-
"target": 0,
968-
"text": "
969-
970-
",
971-
},
972-
"persist": [Function],
973-
"preventDefault": [Function],
974-
"stopPropagation": [Function],
975-
"target": {},
976-
"timeStamp": 0,
977-
},
978-
},
979929
{
980930
"name": "change",
981931
"payload": {

‎src/user-event/type/__tests__/type-managed.test.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ function ManagedTextInput({
3838
onPressOut={logEvent('pressOut')}
3939
onChange={logEvent('change')}
4040
onKeyPress={logEvent('keyPress')}
41-
/** @ts-expect-error property typedef removed in RN 0.75 */
42-
onTextInput={logEvent('textInput')}
4341
onSelectionChange={logEvent('selectionChange')}
4442
onSubmitEditing={logEvent('submitEditing')}
4543
onEndEditing={logEvent('endEditing')}

‎src/user-event/type/__tests__/type.test.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ function renderTextInputWithToolkit(props: TextInputProps = {}) {
2121
onChange={logEvent('change')}
2222
onChangeText={logEvent('changeText')}
2323
onKeyPress={logEvent('keyPress')}
24-
/** @ts-expect-error property typedef removed in RN 0.75 */
25-
onTextInput={logEvent('textInput')}
2624
onSelectionChange={logEvent('selectionChange')}
2725
onSubmitEditing={logEvent('submitEditing')}
2826
onEndEditing={logEvent('endEditing')}
@@ -173,13 +171,11 @@ describe('type()', () => {
173171
'focus',
174172
'pressOut',
175173
'keyPress',
176-
'textInput',
177174
'change',
178175
'changeText',
179176
'selectionChange',
180177
'contentSizeChange',
181178
'keyPress',
182-
'textInput',
183179
'change',
184180
'changeText',
185181
'selectionChange',

‎src/user-event/type/type.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ export async function type(
5555
config: this.config,
5656
key,
5757
text: currentText,
58-
previousText,
5958
isAccepted,
6059
});
6160
}
@@ -76,13 +75,12 @@ type EmitTypingEventsContext = {
7675
config: UserEventConfig;
7776
key: string;
7877
text: string;
79-
previousText: string;
8078
isAccepted?: boolean;
8179
};
8280

8381
export async function emitTypingEvents(
8482
element: ReactTestInstance,
85-
{ config, key, text, previousText, isAccepted }: EmitTypingEventsContext,
83+
{ config, key, text, isAccepted }: EmitTypingEventsContext,
8684
) {
8785
const isMultiline = element.props.multiline === true;
8886

@@ -96,12 +94,6 @@ export async function emitTypingEvents(
9694
return;
9795
}
9896

99-
// According to the docs only multiline TextInput emits textInput event
100-
// @see: https://github.com/facebook/react-native/blob/42a2898617da1d7a98ef574a5b9e500681c8f738/packages/react-native/Libraries/Components/TextInput/TextInput.d.ts#L754
101-
if (isMultiline) {
102-
dispatchEvent(element, 'textInput', EventBuilder.TextInput.textInput(text, previousText));
103-
}
104-
10597
dispatchEvent(element, 'change', EventBuilder.TextInput.change(text));
10698
dispatchEvent(element, 'changeText', text);
10799

0 commit comments

Comments
 (0)
Please sign in to comment.