Skip to content

Commit 37453d0

Browse files
committed
tweaks
1 parent 6661ff5 commit 37453d0

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/user-event/scroll/__tests__/pull-to-refresh.test.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ describe('pullToRefresh()', () => {
6969
await expect(user.pullToRefresh(screen.getByTestId('view'))).resolves.toBeUndefined();
7070
});
7171

72+
test('does not throw when refreshControl is not a valid element', async () => {
73+
// Defensive: `refreshControl` violates its `ReactElement` type and has no `props`.
74+
await render(<ScrollView testID="view" refreshControl={'invalid' as any} />);
75+
const user = userEvent.setup();
76+
77+
await expect(user.pullToRefresh(screen.getByTestId('view'))).resolves.toBeUndefined();
78+
});
79+
7280
test('throws when passed a non-ScrollView element', async () => {
7381
await render(<View testID="view" />);
7482
const user = userEvent.setup();

src/user-event/scroll/pull-to-refresh.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export async function pullToRefresh(
1717
}
1818

1919
const refreshControl = instance.props.refreshControl;
20-
if (refreshControl == null || typeof refreshControl.props.onRefresh !== 'function') {
20+
if (typeof refreshControl?.props?.onRefresh !== 'function') {
2121
return;
2222
}
2323

0 commit comments

Comments
 (0)