Skip to content

Typings for findBy* do not include waitForElement options #366

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

Closed
justinanastos opened this issue Apr 26, 2019 · 4 comments · Fixed by DefinitelyTyped/DefinitelyTyped#41237
Labels
help wanted Extra attention is needed TypeScript Related to TypeScript. Note: only certain maintainers handle TypeScript labeled issues.

Comments

@justinanastos
Copy link

justinanastos commented Apr 26, 2019

  • react-testing-library version: 7.0.0
  • react version: 16.8.4
  • node version: 8.12.0
  • npm (or yarn) version: 6.9.0

Relevant code or config:

const { findByLabelText } = render(
  <div />,
);

expect(await findByLabelText('anything', undefined, { timeout: 100 }))
  .toHaveAttribute(
    'aria-checked',
    'mixed',
  );

What you did:

Per the docs, the findBy queries accept the waitForElement options as the last argument. The TypeScript configuration only reflects a possible 1-2 arguments instead of the expected 1-3.

I suspect this has to do with how RenderResult (

export type RenderResult<Q extends Queries = typeof queries> = {
container: HTMLElement
baseElement: HTMLElement
debug: (baseElement?: HTMLElement | DocumentFragment) => void
rerender: (ui: React.ReactElement<any>) => void
unmount: () => boolean
asFragment: () => DocumentFragment
} & {[P in keyof Q]: BoundFunction<Q[P]>}
export interface RenderOptions<Q extends Queries = typeof queries> {
container?: HTMLElement
baseElement?: HTMLElement
hydrate?: boolean
queries?: Q
wrapper?: React.ComponentType
}
) is union'ed (& {[P in keyof Q]: BoundFunction<Q[P]>) with queries via BoundFunction (https://github.com/testing-library/dom-testing-library/blob/4fb00936cbf5b0d715f5b54d16576dc3bfe20460/typings/get-queries-for-element.d.ts#L4-L14).

I'd love to help; I'm hazy on how exactly the following works; which is where I believe the problem lies:

https://github.com/testing-library/dom-testing-library/blob/4fb00936cbf5b0d715f5b54d16576dc3bfe20460/typings/get-queries-for-element.d.ts#L4-L14

@kentcdodds kentcdodds added help wanted Extra attention is needed TypeScript Related to TypeScript. Note: only certain maintainers handle TypeScript labeled issues. labels Apr 27, 2019
@kentcdodds
Copy link
Member

findBy* queries are a bit unique compared to the other variants, so they may need some special handling.

I don't maintain the TS definitions, so if someone else would like to pitch in here that'd be great :)

@0ubbe
Copy link

0ubbe commented Jul 16, 2019

@kentcdodds

I'm more or less familiar with Typescript and would like to give a go to type this if possible.

I use RTL on most of my projects so really keen to give back ❤️ 👌🏻

@kentcdodds
Copy link
Member

Feel free 👍

@kentcdodds
Copy link
Member

Closing for inactivity. Feel free to open a new issue if it's still a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed TypeScript Related to TypeScript. Note: only certain maintainers handle TypeScript labeled issues.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants