|
1 | 1 | import React from 'react';
|
2 |
| -import { Pressable, Text, TouchableHighlight, TouchableOpacity } from 'react-native'; |
| 2 | +import { Pressable, Text, TouchableHighlight, TouchableOpacity, View } from 'react-native'; |
| 3 | +import type { ReactTestInstance } from 'react-test-renderer'; |
3 | 4 |
|
4 | 5 | import { render, screen } from '../../..';
|
5 | 6 | import { createEventLogger, getEventsNames } from '../../../test-utils';
|
@@ -152,4 +153,35 @@ describe('userEvent.longPress with fake timers', () => {
|
152 | 153 |
|
153 | 154 | expect(mockOnLongPress).toHaveBeenCalled();
|
154 | 155 | });
|
| 156 | + |
| 157 | + test('longPress accepts custom duration', async () => { |
| 158 | + const { events, logEvent } = createEventLogger(); |
| 159 | + const user = userEvent.setup(); |
| 160 | + |
| 161 | + render( |
| 162 | + <Pressable |
| 163 | + onPress={logEvent('press')} |
| 164 | + onPressIn={logEvent('pressIn')} |
| 165 | + onPressOut={logEvent('pressOut')} |
| 166 | + onLongPress={logEvent('longPress')} |
| 167 | + testID="pressable" |
| 168 | + />, |
| 169 | + ); |
| 170 | + |
| 171 | + await user.longPress(screen.getByTestId('pressable'), { duration: 250 }); |
| 172 | + expect(getEventsNames(events)).toEqual(['pressIn', 'pressOut', 'press']); |
| 173 | + }); |
| 174 | + |
| 175 | + it('longPress throws on composite components', async () => { |
| 176 | + render(<View testID="view" />); |
| 177 | + const user = userEvent.setup(); |
| 178 | + |
| 179 | + const compositeView = screen.getByTestId('view').parent as ReactTestInstance; |
| 180 | + await expect(user.press(compositeView)).rejects.toThrowErrorMatchingInlineSnapshot(` |
| 181 | + "press() works only with host elements. Passed element has type "function Component() { |
| 182 | + (0, _classCallCheck2.default)(this, Component); |
| 183 | + return _callSuper(this, Component, arguments); |
| 184 | + }"." |
| 185 | + `); |
| 186 | + }); |
155 | 187 | });
|
0 commit comments