Skip to content

Commit 0ab85c6

Browse files
committed
feat: add setup test utils to use user events
1 parent a46693e commit 0ab85c6

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/core/test-utils.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import '@shopify/flash-list/jestSetup';
33
import { BottomSheetModalProvider } from '@gorhom/bottom-sheet';
44
import { NavigationContainer } from '@react-navigation/native';
55
import type { RenderOptions } from '@testing-library/react-native';
6-
import { render } from '@testing-library/react-native';
6+
import { render, userEvent } from '@testing-library/react-native';
77
import type { ReactElement } from 'react';
88
import React from 'react';
99

@@ -17,11 +17,23 @@ const createAppWrapper = () => {
1717

1818
const customRender = (
1919
ui: ReactElement,
20-
options?: Omit<RenderOptions, 'wrapper'>
20+
options?: Omit<RenderOptions, 'wrapper'>,
2121
) => {
2222
const Wrapper = createAppWrapper(); // make sure we have a new wrapper for each render
2323
return render(ui, { wrapper: Wrapper, ...options });
2424
};
2525

26+
// use this if you want to test user events
27+
export const setup = (
28+
ui: ReactElement,
29+
options?: Omit<RenderOptions, 'wrapper'>,
30+
) => {
31+
const Wrapper = createAppWrapper();
32+
return {
33+
user: userEvent.setup(),
34+
...render(ui, { wrapper: Wrapper, ...options }),
35+
};
36+
};
37+
2638
export * from '@testing-library/react-native';
2739
export { customRender as render };

0 commit comments

Comments
 (0)