Skip to content

Commit 327f1f1

Browse files
author
pierrezimmermann
committed
refactor: split test in longPress in two
1 parent c131447 commit 327f1f1

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,46 @@ describe('userEvent.longPress with real timers', () => {
2727
expect(mockOnLongPress).toHaveBeenCalled();
2828
});
2929

30-
test('calls onLongPress when duration is greater than specified onLongPressDelay', async () => {
30+
test('calls onLongPress when duration is greater than specified longPressDelay', async () => {
3131
const mockOnLongPress = jest.fn();
3232
const mockOnPress = jest.fn();
3333
const user = userEvent.setup();
3434

3535
render(
3636
<Pressable
37-
delayLongPress={1000}
37+
delayLongPress={800}
3838
onLongPress={mockOnLongPress}
3939
onPress={mockOnPress}
4040
>
4141
<Text>press me</Text>
4242
</Pressable>
4343
);
44-
await user.longPress(screen.getByText('press me'));
45-
46-
expect(mockOnLongPress).not.toHaveBeenCalled();
47-
expect(mockOnPress).toHaveBeenCalledTimes(1);
4844

4945
await user.longPress(screen.getByText('press me'), {
5046
duration: 1000,
5147
});
5248

5349
expect(mockOnLongPress).toHaveBeenCalled();
50+
expect(mockOnPress).not.toHaveBeenCalled();
51+
});
52+
53+
test('does not calls onLongPress when duration is lesser than specified longPressDelay', async () => {
54+
const mockOnLongPress = jest.fn();
55+
const mockOnPress = jest.fn();
56+
const user = userEvent.setup();
57+
58+
render(
59+
<Pressable
60+
delayLongPress={1000}
61+
onLongPress={mockOnLongPress}
62+
onPress={mockOnPress}
63+
>
64+
<Text>press me</Text>
65+
</Pressable>
66+
);
67+
await user.longPress(screen.getByText('press me'));
68+
69+
expect(mockOnLongPress).not.toHaveBeenCalled();
5470
expect(mockOnPress).toHaveBeenCalledTimes(1);
5571
});
5672

src/user-event/press/__tests__/longPress.test.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,39 @@ describe('userEvent.longPress with fake timers', () => {
2929

3030
render(
3131
<Pressable
32-
delayLongPress={1000}
32+
delayLongPress={800}
3333
onLongPress={mockOnLongPress}
3434
onPress={mockOnPress}
3535
>
3636
<Text>press me</Text>
3737
</Pressable>
3838
);
39-
await user.longPress(screen.getByText('press me'));
40-
41-
expect(mockOnLongPress).not.toHaveBeenCalled();
42-
expect(mockOnPress).toHaveBeenCalledTimes(1);
4339

4440
await user.longPress(screen.getByText('press me'), {
4541
duration: 1000,
4642
});
4743

4844
expect(mockOnLongPress).toHaveBeenCalled();
45+
expect(mockOnPress).not.toHaveBeenCalled();
46+
});
47+
48+
test('does not calls onLongPress when duration is lesser than specified onLongPressDelay', async () => {
49+
const mockOnLongPress = jest.fn();
50+
const mockOnPress = jest.fn();
51+
const user = userEvent.setup();
52+
53+
render(
54+
<Pressable
55+
delayLongPress={1000}
56+
onLongPress={mockOnLongPress}
57+
onPress={mockOnPress}
58+
>
59+
<Text>press me</Text>
60+
</Pressable>
61+
);
62+
await user.longPress(screen.getByText('press me'));
63+
64+
expect(mockOnLongPress).not.toHaveBeenCalled();
4965
expect(mockOnPress).toHaveBeenCalledTimes(1);
5066
});
5167

0 commit comments

Comments
 (0)