Skip to content

Commit

Permalink
fix(types): Allow all HTML and SVG elements in render. (#833)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian Silbermann <silbermann.sebastian@gmail.com>
  • Loading branch information
joebobmiles and eps1lon committed Nov 19, 2020
1 parent 456424f commit 1dc33b2
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import {act as reactAct} from 'react-dom/test-utils'
export * from '@testing-library/dom'

export type RenderResult<Q extends Queries = typeof queries> = {
container: HTMLElement
baseElement: HTMLElement
container: Element
baseElement: Element
debug: (
baseElement?:
| HTMLElement
| Element
| DocumentFragment
| Array<HTMLElement | DocumentFragment>,
| Array<Element | DocumentFragment>,
maxLength?: number,
options?: prettyFormat.OptionsReceived,
) => void
Expand All @@ -27,8 +27,8 @@ export type RenderResult<Q extends Queries = typeof queries> = {
} & {[P in keyof Q]: BoundFunction<Q[P]>}

export interface RenderOptions<Q extends Queries = typeof queries> {
container?: HTMLElement
baseElement?: HTMLElement
container?: Element
baseElement?: Element
hydrate?: boolean
queries?: Q
wrapper?: React.ComponentType
Expand Down

3 comments on commit 1dc33b2

@ducin
Copy link

@ducin ducin commented on 1dc33b2 Dec 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joebobmiles @eps1lon
Dear All,

I'm afraid this commit introduces unnecessary compilation errors in TS:

  • RTL's render function returns an object with container: Element, as shown above
  • all queries, such as getByTestId et all, require container to be HTMLElement. Yes, you can have a bound getByTestId when you extract it from render's result, but you can also import it directly from RTL and use it in an unbound fashion. Sometimes you have to do that!
  • all in all it boils down to HTMLElement being Element, but Element not necessarily being HTMLElement (subtype, covariance)

As a consequence, I can't pass the container from render into getByTestId. And I think I should be able to (no compiler errors should arise).

@eps1lon
Copy link
Member

@eps1lon eps1lon commented on 1dc33b2 Dec 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ducin Sorry to hear you're having trouble. Would you be so kind and open an issue that follows the template? This helps us triage and track the issue.

@MatanBobi
Copy link
Member

@MatanBobi MatanBobi commented on 1dc33b2 Dec 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joebobmiles @eps1lon
Dear All,

I'm afraid this commit introduces unnecessary compilation errors in TS:

  • RTL's render function returns an object with container: Element, as shown above
  • all queries, such as getByTestId et all, require container to be HTMLElement. Yes, you can have a bound getByTestId when you extract it from render's result, but you can also import it directly from RTL and use it in an unbound fashion. Sometimes you have to do that!
  • all in all it boils down to HTMLElement being Element, but Element not necessarily being HTMLElement (subtype, covariance)

As a consequence, I can't pass the container from render into getByTestId. And I think I should be able to (no compiler errors should arise).

Hi @ducin thanks for sharing this.
We already have a PR going to fix that and these two issues relate to it: #841, testing-library/dom-testing-library#838. You can follow our progress here: testing-library/dom-testing-library#834

Please sign in to comment.