Skip to content

Typings for findBy* do not include waitForElement options #366

Closed
DefinitelyTyped/DefinitelyTyped
#41237
@justinanastos

Description

@justinanastos
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    TypeScriptRelated to TypeScript. Note: only certain maintainers handle TypeScript labeled issues.help wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions