Skip to content

Commit 30f89bf

Browse files
committed
chore: fix edge case press event sequence
1 parent 54dcd5f commit 30f89bf

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/__tests__/react-native-gesture-handler.test.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,10 @@ test('userEvent can invoke press events for RNGH Pressable', async () => {
5757

5858
const pressable = screen.getByTestId('pressable');
5959
await user.press(pressable);
60-
expect(getEventsNames(events)).toEqual(['pressIn', 'pressOut', 'press']);
60+
61+
// Typical event order is pressIn, pressOut, press
62+
// But sometimes due to a race condition, the order is pressIn, press, pressOut.
63+
expect(['pressIn,pressOut,press', 'pressIn,press,pressOut']).toContain(
64+
getEventsNames(events).join(','),
65+
);
6166
});

src/user-event/press/__tests__/press.real-timers.test.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ describe('userEvent.press with real timers', () => {
3636
await user.press(screen.getByTestId('pressable'));
3737
// Typical event order is pressIn, pressOut, press
3838
// But sometimes due to a race condition, the order is pressIn, press, pressOut.
39-
const eventSequence = getEventsNames(events).join(', ');
40-
expect(
41-
eventSequence === 'pressIn, pressOut, press' || eventSequence === 'pressIn, press, pressOut',
42-
).toBe(true);
39+
expect(['pressIn,pressOut,press', 'pressIn,press,pressOut']).toContain(
40+
getEventsNames(events).join(','),
41+
);
4342
});
4443

4544
test('works on TouchableOpacity', async () => {
@@ -203,12 +202,11 @@ describe('userEvent.press with real timers', () => {
203202
);
204203
await user.press(screen.getByTestId('pressable'));
205204

206-
const eventSequence = getEventsNames(events).join(', ');
207205
// Typical event order is pressIn, pressOut, press
208206
// But sometimes due to a race condition, the order is pressIn, press, pressOut.
209-
expect(
210-
eventSequence === 'pressIn, pressOut, press' || eventSequence === 'pressIn, press, pressOut',
211-
).toBe(true);
207+
expect(['pressIn,pressOut,press', 'pressIn,press,pressOut']).toContain(
208+
getEventsNames(events).join(','),
209+
);
212210
});
213211

214212
test('crawls up in the tree to find an element that responds to touch events', async () => {

0 commit comments

Comments
 (0)