From b410e396228ff9027144c7c0b008db9f5165f220 Mon Sep 17 00:00:00 2001 From: Karl Dominick Cinco Date: Wed, 28 Nov 2018 02:28:44 +0800 Subject: [PATCH] fix: modify *ByType API TS typings to allow required props (#71) --- typings/__tests__/index.test.tsx | 19 +++++++++++++++++++ typings/index.d.ts | 10 ++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/typings/__tests__/index.test.tsx b/typings/__tests__/index.test.tsx index c8582709..4b1d744d 100644 --- a/typings/__tests__/index.test.tsx +++ b/typings/__tests__/index.test.tsx @@ -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) => ( + {props.requiredProp} +); const TestComponent = () => ( @@ -24,6 +31,9 @@ const tree = render(); 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(''); const getByTextRegExp: ReactTestInstance = tree.getByText(/View/g); const getByProps: ReactTestInstance = tree.getByProps({ value: 2 }); @@ -33,6 +43,9 @@ const getAllByNameConstructor: Array = tree.getAllByName( View ); const getAllByType: Array = tree.getAllByType(View); +const getAllByTypeWithRequiredProps: Array< + ReactTestInstance +> = tree.getAllByType(ElementWithRequiredProps); const getAllByTextString: Array = tree.getAllByText( '' ); @@ -45,6 +58,9 @@ const getAllByProps: Array = 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( '' ); @@ -58,6 +74,9 @@ const queryAllByNameConstructor: Array = tree.getAllByName( View ); const queryAllByType: Array = tree.getAllByType(View); +const queryAllByTypeWithRequiredProps: Array< + ReactTestInstance +> = tree.getAllByType(ElementWithRequiredProps); const queryAllByTextString: Array = tree.queryAllByText( 'View' ); diff --git a/typings/index.d.ts b/typings/index.d.ts index bc3ab1f0..d1ce52fd 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -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:

(type: React.ComponentType

) => ReactTestInstance; getByText: (text: string | RegExp) => ReactTestInstance; getByProps: (props: Record) => ReactTestInstance; getByTestId: (testID: string) => ReactTestInstance; getAllByName: (name: React.ReactType) => Array; - getAllByType: (type: React.ComponentType) => Array; + getAllByType:

(type: React.ComponentType

) => Array; getAllByText: (text: string | RegExp) => Array; getAllByProps: (props: Record) => Array; } export interface QueryByAPI { queryByName: (name: React.ReactType) => ReactTestInstance | null; - queryByType: (type: React.ComponentType) => ReactTestInstance | null; + queryByType:

(type: React.ComponentType

) => ReactTestInstance | null; queryByText: (name: string | RegExp) => ReactTestInstance | null; queryByProps: (props: Record) => ReactTestInstance | null; queryByTestId: (testID: string) => ReactTestInstance | null; queryAllByName: (name: React.ReactType) => Array | []; - queryAllByType: (type: React.ComponentType) => Array | []; + queryAllByType:

( + type: React.ComponentType

+ ) => Array | []; queryAllByText: (text: string | RegExp) => Array | []; queryAllByProps: ( props: Record