mirror of
https://github.com/callstack/react-native-testing-library.git
synced 2026-09-18 23:09:04 +08:00
feat: add getAllByTestId and queryAllByTestId queries (#198)
* feat: add getAllByTestId and queryAllByTestId queries * Add test for getAllByTestId and queryAllByTestId - Filter out intermediate components in getAllByTestId. testIDs may be passed down to child components and appearing multiple times in the render tree. Some React Native components render multiple anyways. <Text> is an example. * Update TypeScript typings * Fix flow types * Update TS typings test
This commit is contained in:
committed by
Michał Pierzchała
parent
9369efee73
commit
fead652013
@@ -54,6 +54,7 @@ const getByDisplayValueRegExp: ReactTestInstance = tree.getByDisplayValue(
|
||||
);
|
||||
const getByProps: ReactTestInstance = tree.getByProps({ value: 2 });
|
||||
const getByTestId: ReactTestInstance = tree.getByTestId('test-id');
|
||||
const getAllByTestId: ReactTestInstance[] = tree.getAllByTestId('test-id');
|
||||
const getAllByNameString: Array<ReactTestInstance> = tree.getAllByName('View');
|
||||
const getAllByNameConstructor: Array<ReactTestInstance> = tree.getAllByName(
|
||||
View
|
||||
@@ -93,6 +94,9 @@ const queryByDisplayValueRegExp: ReactTestInstance | null = tree.queryByDisplayV
|
||||
);
|
||||
const queryByProps: ReactTestInstance | null = tree.queryByProps({ value: 2 });
|
||||
const queryByTestId: ReactTestInstance | null = tree.queryByTestId('test-id');
|
||||
const queryAllByTestId: ReactTestInstance[] | null = tree.queryAllByTestId(
|
||||
'test-id'
|
||||
);
|
||||
const queryAllByNameString: Array<ReactTestInstance> = tree.queryAllByName(
|
||||
'View'
|
||||
);
|
||||
|
||||
Vendored
+2
@@ -9,6 +9,7 @@ export interface GetByAPI {
|
||||
getByDisplayValue: (value: string | RegExp) => ReactTestInstance;
|
||||
getByProps: (props: Record<string, any>) => ReactTestInstance;
|
||||
getByTestId: (testID: string) => ReactTestInstance;
|
||||
getAllByTestId: (testID: string) => Array<ReactTestInstance>;
|
||||
getAllByName: (name: React.ReactType | string) => Array<ReactTestInstance>;
|
||||
getAllByType: <P>(type: React.ComponentType<P>) => Array<ReactTestInstance>;
|
||||
getAllByText: (text: string | RegExp) => Array<ReactTestInstance>;
|
||||
@@ -29,6 +30,7 @@ export interface QueryByAPI {
|
||||
queryByDisplayValue: (value: string | RegExp) => ReactTestInstance | null;
|
||||
queryByProps: (props: Record<string, any>) => ReactTestInstance | null;
|
||||
queryByTestId: (testID: string) => ReactTestInstance | null;
|
||||
queryAllByTestId: (testID: string) => Array<ReactTestInstance> | null;
|
||||
queryAllByName: (
|
||||
name: React.ReactType | string
|
||||
) => Array<ReactTestInstance> | [];
|
||||
|
||||
Reference in New Issue
Block a user