-
Notifications
You must be signed in to change notification settings - Fork 274
Adding support for extending with custom queries #573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,7 +137,10 @@ interface FindByAPI { | |
value: string | RegExp, | ||
waitForOptions?: WaitForOptions | ||
) => FindReturn; | ||
findByTestId: (testID: string | RegExp, waitForOptions?: WaitForOptions) => FindReturn; | ||
findByTestId: ( | ||
testID: string | RegExp, | ||
waitForOptions?: WaitForOptions | ||
) => FindReturn; | ||
findAllByText: ( | ||
text: string | RegExp, | ||
waitForOptions?: WaitForOptions | ||
|
@@ -293,6 +296,9 @@ export interface Thenable { | |
export interface RenderOptions { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I check RTL/DTL and they seem to have quite decent TS typings for custom queries: export type Query = (
container: HTMLElement,
...args: any[]
) => Error | Promise<HTMLElement[]> | Promise<HTMLElement> | HTMLElement[] | HTMLElement | null;
export interface Queries {
[T: string]: Query;
} export type RenderResult<Q extends Queries = typeof queries> = {
// ...
} & {[P in keyof Q]: BoundFunction<Q[P]>}
export interface RenderOptions<Q extends Queries = typeof queries> {
// ...
queries?: Q
} Source: https://github.com/testing-library/react-testing-library/blob/master/types/index.d.ts IMO we could have the same at least for TS, possibly for flow as well if possible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please note that the |
||
wrapper?: React.ComponentType<any>; | ||
createNodeMock?: (element: React.ReactElement<any>) => any; | ||
queries?: { | ||
[key: string]: (instance: ReactTestInstance, ...rest: Array<any>) => any; | ||
}; | ||
} | ||
|
||
type Queries = GetByAPI & QueryByAPI & FindByAPI & A11yAPI; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Struggling a bit on how to type it better, so that custom queries are inferred without forced generics. We can improve it later though