Skip to content

Commit 27d6d97

Browse files
committed
refactor: final tweaks
1 parent 31f6b90 commit 27d6d97

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import * as React from 'react';
22
import { TextInput, TextInputProps, View } from 'react-native';
3-
import {
4-
createEventLogger,
5-
getEventsNames,
6-
lastEvent,
7-
lastEventPayload,
8-
} from '../../../test-utils';
3+
import { createEventLogger, getEventsNames, lastEventPayload } from '../../../test-utils';
94
import { render, screen } from '../../..';
105
import { userEvent } from '../..';
116

src/user-event/type/type.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,8 @@ export async function type(
4848
for (const key of keys) {
4949
const previousText = element.props.value ?? currentText;
5050
const proposedText = applyKey(previousText, key);
51-
let isAccepted = false;
52-
if (isTextChangeAllowed(element, proposedText)) {
53-
currentText = proposedText;
54-
isAccepted = true;
55-
}
51+
const isAccepted = isTextChangeAccepted(element, proposedText);
52+
currentText = isAccepted ? proposedText : previousText;
5653

5754
await emitTypingEvents(element, {
5855
config: this.config,
@@ -138,7 +135,7 @@ function applyKey(text: string, key: string) {
138135
return text + key;
139136
}
140137

141-
function isTextChangeAllowed(element: ReactTestInstance, text: string) {
138+
function isTextChangeAccepted(element: ReactTestInstance, text: string) {
142139
const maxLength = element.props.maxLength;
143140
return maxLength === undefined || text.length <= maxLength;
144141
}

0 commit comments

Comments
 (0)