-
Notifications
You must be signed in to change notification settings - Fork 29
Add find* queries #44
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import {Matcher, MatcherOptions, SelectorMatcherOptions} from '@testing-library/dom' | ||
import {Matcher, MatcherOptions, SelectorMatcherOptions, WaitForElementOptions} from '@testing-library/dom' | ||
import {ElementHandle} from 'puppeteer' | ||
|
||
type Element = ElementHandle | ||
|
@@ -8,54 +8,144 @@ interface IQueryMethods { | |
queryAllByPlaceholderText(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element[]> | ||
getByPlaceholderText(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element> | ||
getAllByPlaceholderText(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element[]> | ||
findByPlaceholderText( | ||
el: Element, | ||
m: Matcher, | ||
opts?: SelectorMatcherOptions, | ||
waitForOpts?: WaitForElementOptions): Promise<Element> | ||
findAllByPlaceholderText( | ||
el: Element, | ||
m: Matcher, | ||
opts?: SelectorMatcherOptions, | ||
waitForOpts?: WaitForElementOptions): Promise<Element[]> | ||
|
||
queryByText(el: Element, m: Matcher, opts?: SelectorMatcherOptions): Promise<Element | null> | ||
queryAllByText(el: Element, m: Matcher, opts?: SelectorMatcherOptions): Promise<Element[]> | ||
getByText(el: Element, m: Matcher, opts?: SelectorMatcherOptions): Promise<Element> | ||
getAllByText(el: Element, m: Matcher, opts?: SelectorMatcherOptions): Promise<Element[]> | ||
findByText( | ||
el: Element, | ||
m: Matcher, | ||
opts?: SelectorMatcherOptions, | ||
waitForOpts?: WaitForElementOptions): Promise<Element> | ||
findAllByText( | ||
el: Element, | ||
m: Matcher, | ||
opts?: SelectorMatcherOptions, | ||
waitForOpts?: WaitForElementOptions): Promise<Element[]> | ||
|
||
queryByLabelText(el: Element, m: Matcher, opts?: SelectorMatcherOptions): Promise<Element | null> | ||
queryAllByLabelText(el: Element, m: Matcher, opts?: SelectorMatcherOptions): Promise<Element[]> | ||
getByLabelText(el: Element, m: Matcher, opts?: SelectorMatcherOptions): Promise<Element> | ||
getAllByLabelText(el: Element, m: Matcher, opts?: SelectorMatcherOptions): Promise<Element[]> | ||
findByLabelText( | ||
el: Element, | ||
m: Matcher, | ||
opts?: SelectorMatcherOptions, | ||
waitForOpts?: WaitForElementOptions): Promise<Element> | ||
findAllByLabelText( | ||
el: Element, | ||
m: Matcher, | ||
opts?: SelectorMatcherOptions, | ||
waitForOpts?: WaitForElementOptions): Promise<Element[]> | ||
|
||
queryByAltText(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element | null> | ||
queryAllByAltText(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element[]> | ||
getByAltText(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element> | ||
getAllByAltText(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element[]> | ||
findByAltText( | ||
el: Element, | ||
m: Matcher, | ||
opts?: SelectorMatcherOptions, | ||
waitForOpts?: WaitForElementOptions): Promise<Element> | ||
findAllByAltText( | ||
el: Element, | ||
m: Matcher, | ||
opts?: SelectorMatcherOptions, | ||
waitForOpts?: WaitForElementOptions): Promise<Element[]> | ||
|
||
queryByTestId(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element | null> | ||
queryAllByTestId(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element[]> | ||
getByTestId(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element> | ||
getAllByTestId(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element[]> | ||
findByTestId( | ||
el: Element, | ||
m: Matcher, | ||
opts?: SelectorMatcherOptions, | ||
waitForOpts?: WaitForElementOptions): Promise<Element> | ||
findAllByTestId( | ||
el: Element, | ||
m: Matcher, | ||
opts?: SelectorMatcherOptions, | ||
waitForOpts?: WaitForElementOptions): Promise<Element[]> | ||
|
||
queryByTitle(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element | null> | ||
queryAllByTitle(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element[]> | ||
getByTitle(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element> | ||
getAllByTitle(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element[]> | ||
findByTitle( | ||
el: Element, | ||
m: Matcher, | ||
opts?: SelectorMatcherOptions, | ||
waitForOpts?: WaitForElementOptions): Promise<Element> | ||
findAllByTitle( | ||
el: Element, | ||
m: Matcher, | ||
opts?: SelectorMatcherOptions, | ||
waitForOpts?: WaitForElementOptions): Promise<Element[]> | ||
|
||
queryByRole(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element | null> | ||
queryAllByRole(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element[]> | ||
getByRole(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element> | ||
getAllByRole(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element[]> | ||
findByRole( | ||
el: Element, | ||
m: Matcher, | ||
opts?: SelectorMatcherOptions, | ||
waitForOpts?: WaitForElementOptions): Promise<Element> | ||
findAllByRole( | ||
el: Element, | ||
m: Matcher, | ||
opts?: SelectorMatcherOptions, | ||
waitForOpts?: WaitForElementOptions): Promise<Element[]> | ||
|
||
queryByDisplayValue(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element | null> | ||
queryAllByDisplayValue(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element[]> | ||
getByDisplayValue(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element> | ||
getAllByDisplayValue(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element[]> | ||
findByDisplayValue( | ||
el: Element, | ||
m: Matcher, | ||
opts?: SelectorMatcherOptions, | ||
waitForOpts?: WaitForElementOptions): Promise<Element> | ||
findAllByDisplayValue( | ||
el: Element, | ||
m: Matcher, | ||
opts?: SelectorMatcherOptions, | ||
waitForOpts?: WaitForElementOptions): Promise<Element[]> | ||
} | ||
|
||
type IScopedQueryMethods = { | ||
[K in keyof IQueryMethods]: (m: Matcher, opts?: MatcherOptions) => ReturnType<IQueryMethods[K]> | ||
} | ||
export type BoundFunction<T> = T extends ( | ||
attribute: string, | ||
element: Element, | ||
text: infer P, | ||
options: infer Q, | ||
) => infer R | ||
? (text: P, options?: Q) => R | ||
: T extends (a1: any, text: infer P, options: infer Q, waitForElementOptions: infer W) => infer R | ||
? (text: P, options?: Q, waitForElementOptions?: W) => R | ||
: T extends (a1: any, text: infer P, options: infer Q) => infer R | ||
? (text: P, options?: Q) => R | ||
: never | ||
export type BoundFunctions<T> = { [P in keyof T]: BoundFunction<T[P]> } | ||
|
||
export interface IScopedQueryUtils extends IScopedQueryMethods { | ||
getQueriesForElement(): IQueryUtils & IScopedQueryUtils | ||
export interface IScopedQueryUtils extends BoundFunctions<IQueryMethods> { | ||
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'm not sure I know it's a pain, but maybe we just have to write our own type inference or just add 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. We could duplicate |
||
getQueriesForElement(): IScopedQueryUtils | ||
getNodeText(): Promise<string> | ||
} | ||
|
||
export interface IQueryUtils extends IQueryMethods { | ||
getQueriesForElement(): IQueryUtils & IScopedQueryUtils | ||
getQueriesForElement(): IScopedQueryUtils | ||
getNodeText(el: Element): Promise<string> | ||
} | ||
|
||
|
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.
I'm not sure we want to remove this note, but maybe convert it to cover
waitForDomChange
andwaitForElementToBeRemoved
as well and nudge to "use thefind*
methods instead".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.
Check latest commit, writing documentation is hard 😁
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.
We can't use
find*
queries forwaitForElementToBeRemoved
, but I think we should be able to get that working nicely. Didn't get round to it in this PR but I'll raise an issue if anyone else wants to do it :)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.
sounds good thanks! :)