Skip to content

Commit 44b3a36

Browse files
committed
refactor: tweaks
1 parent aa96951 commit 44b3a36

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/user-event/press/press.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface PressOptions {
2020
export async function press(this: UserEventInstance, element: ReactTestInstance): Promise<void> {
2121
await basePress(this.config, element, {
2222
type: 'press',
23-
duration: DEFAULT_MIN_PRESS_DURATION,
23+
duration: undefined,
2424
});
2525
}
2626

@@ -37,7 +37,7 @@ export async function longPress(
3737

3838
interface BasePressOptions {
3939
type: 'press' | 'longPress';
40-
duration: number;
40+
duration: number | undefined;
4141
}
4242

4343
const basePress = async (
@@ -77,16 +77,17 @@ const emitPressablePressEvents = async (
7777

7878
dispatchEvent(element, 'responderGrant', EventBuilder.Common.responderGrant());
7979

80-
await wait(config, options.duration);
80+
const duration = options.duration ?? DEFAULT_MIN_PRESS_DURATION;
81+
await wait(config, duration);
8182

8283
dispatchEvent(element, 'responderRelease', EventBuilder.Common.responderRelease());
8384

8485
// React Native will wait for minimal delay of DEFAULT_MIN_PRESS_DURATION
8586
// before emitting the `pressOut` event. We need to wait here, so that
8687
// `press()` function does not return before that.
87-
if (DEFAULT_MIN_PRESS_DURATION - options.duration > 0) {
88+
if (DEFAULT_MIN_PRESS_DURATION - duration > 0) {
8889
await act(async () => {
89-
await wait(config, DEFAULT_MIN_PRESS_DURATION - options.duration);
90+
await wait(config, DEFAULT_MIN_PRESS_DURATION - duration);
9091
});
9192
}
9293
};

0 commit comments

Comments
 (0)