Skip to content

Commit 23ad2ff

Browse files
committed
code coverage
1 parent f31038c commit 23ad2ff

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

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

+33-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
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';
34

45
import { render, screen } from '../../..';
56
import { createEventLogger, getEventsNames } from '../../../test-utils';
@@ -152,4 +153,35 @@ describe('userEvent.longPress with fake timers', () => {
152153

153154
expect(mockOnLongPress).toHaveBeenCalled();
154155
});
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+
});
155187
});

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

+14
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
TouchableOpacity,
99
View,
1010
} from 'react-native';
11+
import type { ReactTestInstance } from 'react-test-renderer';
1112

1213
import { render, screen } from '../../..';
1314
import { createEventLogger, getEventsNames } from '../../../test-utils';
@@ -331,6 +332,19 @@ describe('userEvent.press with fake timers', () => {
331332
expect(mockOnPress).toHaveBeenCalled();
332333
});
333334

335+
it('press throws on composite components', async () => {
336+
render(<View testID="view" />);
337+
const user = userEvent.setup();
338+
339+
const compositeView = screen.getByTestId('view').parent as ReactTestInstance;
340+
await expect(user.press(compositeView)).rejects.toThrowErrorMatchingInlineSnapshot(`
341+
"press() works only with host elements. Passed element has type "function Component() {
342+
(0, _classCallCheck2.default)(this, Component);
343+
return _callSuper(this, Component, arguments);
344+
}"."
345+
`);
346+
});
347+
334348
test('disables act environmennt', async () => {
335349
// In this test there is state update during await when typing
336350
// Since wait is not wrapped by act there would be a warning

0 commit comments

Comments
 (0)