mirror of
https://github.com/callstack/react-native-testing-library.git
synced 2026-09-18 23:09:04 +08:00
fix: modify *ByType API TS typings to allow required props (#71)
This commit is contained in:
committed by
Michał Pierzchała
parent
3f2fc16ec2
commit
b410e39622
@@ -9,8 +9,15 @@ import {
|
||||
waitForElement,
|
||||
} from '../..';
|
||||
|
||||
interface HasRequiredProp {
|
||||
requiredProp: string;
|
||||
}
|
||||
|
||||
const View = props => props.children;
|
||||
const Text = props => props.children;
|
||||
const ElementWithRequiredProps = (props: HasRequiredProp) => (
|
||||
<Text>{props.requiredProp}</Text>
|
||||
);
|
||||
|
||||
const TestComponent = () => (
|
||||
<View>
|
||||
@@ -24,6 +31,9 @@ const tree = render(<TestComponent />);
|
||||
const getByNameString: ReactTestInstance = tree.getByName('View');
|
||||
const getByNameContructor: ReactTestInstance = tree.getByName(View);
|
||||
const getByType: ReactTestInstance = tree.getByType(View);
|
||||
const getByTypeWithRequiredProps: ReactTestInstance = tree.getByType(
|
||||
ElementWithRequiredProps
|
||||
);
|
||||
const getByTextString: ReactTestInstance = tree.getByText('<View />');
|
||||
const getByTextRegExp: ReactTestInstance = tree.getByText(/View/g);
|
||||
const getByProps: ReactTestInstance = tree.getByProps({ value: 2 });
|
||||
@@ -33,6 +43,9 @@ const getAllByNameConstructor: Array<ReactTestInstance> = tree.getAllByName(
|
||||
View
|
||||
);
|
||||
const getAllByType: Array<ReactTestInstance> = tree.getAllByType(View);
|
||||
const getAllByTypeWithRequiredProps: Array<
|
||||
ReactTestInstance
|
||||
> = tree.getAllByType(ElementWithRequiredProps);
|
||||
const getAllByTextString: Array<ReactTestInstance> = tree.getAllByText(
|
||||
'<View />'
|
||||
);
|
||||
@@ -45,6 +58,9 @@ const getAllByProps: Array<ReactTestInstance> = tree.getAllByProps({
|
||||
const queryByNameString: ReactTestInstance | null = tree.queryByName('View');
|
||||
const queryByNameConstructor: ReactTestInstance | null = tree.queryByName(View);
|
||||
const queryByType: ReactTestInstance | null = tree.queryByType(View);
|
||||
const queryByTypeWithRequiredProps: ReactTestInstance | null = tree.queryByType(
|
||||
ElementWithRequiredProps
|
||||
);
|
||||
const queryByTextString: ReactTestInstance | null = tree.queryByText(
|
||||
'<View />'
|
||||
);
|
||||
@@ -58,6 +74,9 @@ const queryAllByNameConstructor: Array<ReactTestInstance> = tree.getAllByName(
|
||||
View
|
||||
);
|
||||
const queryAllByType: Array<ReactTestInstance> = tree.getAllByType(View);
|
||||
const queryAllByTypeWithRequiredProps: Array<
|
||||
ReactTestInstance
|
||||
> = tree.getAllByType(ElementWithRequiredProps);
|
||||
const queryAllByTextString: Array<ReactTestInstance> = tree.queryAllByText(
|
||||
'View'
|
||||
);
|
||||
|
||||
Vendored
+6
-4
@@ -3,24 +3,26 @@ import { ReactTestInstance, ReactTestRendererJSON } from 'react-test-renderer';
|
||||
|
||||
export interface GetByAPI {
|
||||
getByName: (name: React.ReactType) => ReactTestInstance;
|
||||
getByType: (type: React.ComponentType) => ReactTestInstance;
|
||||
getByType: <P>(type: React.ComponentType<P>) => ReactTestInstance;
|
||||
getByText: (text: string | RegExp) => ReactTestInstance;
|
||||
getByProps: (props: Record<string, any>) => ReactTestInstance;
|
||||
getByTestId: (testID: string) => ReactTestInstance;
|
||||
getAllByName: (name: React.ReactType) => Array<ReactTestInstance>;
|
||||
getAllByType: (type: React.ComponentType) => Array<ReactTestInstance>;
|
||||
getAllByType: <P>(type: React.ComponentType<P>) => Array<ReactTestInstance>;
|
||||
getAllByText: (text: string | RegExp) => Array<ReactTestInstance>;
|
||||
getAllByProps: (props: Record<string, any>) => Array<ReactTestInstance>;
|
||||
}
|
||||
|
||||
export interface QueryByAPI {
|
||||
queryByName: (name: React.ReactType) => ReactTestInstance | null;
|
||||
queryByType: (type: React.ComponentType) => ReactTestInstance | null;
|
||||
queryByType: <P>(type: React.ComponentType<P>) => ReactTestInstance | null;
|
||||
queryByText: (name: string | RegExp) => ReactTestInstance | null;
|
||||
queryByProps: (props: Record<string, any>) => ReactTestInstance | null;
|
||||
queryByTestId: (testID: string) => ReactTestInstance | null;
|
||||
queryAllByName: (name: React.ReactType) => Array<ReactTestInstance> | [];
|
||||
queryAllByType: (type: React.ComponentType) => Array<ReactTestInstance> | [];
|
||||
queryAllByType: <P>(
|
||||
type: React.ComponentType<P>
|
||||
) => Array<ReactTestInstance> | [];
|
||||
queryAllByText: (text: string | RegExp) => Array<ReactTestInstance> | [];
|
||||
queryAllByProps: (
|
||||
props: Record<string, any>
|
||||
|
||||
Reference in New Issue
Block a user