Skip to content

types: error in the baseElement typings #1004

Closed
@dshuvalov

Description

@dshuvalov
  • @testing-library/react version: 12.1.2
  • Testing Framework and version: [email protected]
  • DOM Environment: jsdom

Relevant code or config:

it(`SHOULD open modal window WHEN user click on show button`, () => {
    const { baseElement } = render(<ControlledModalExample />)
    expect(screen.queryByTestId(dataTestId)).toBeNull()
    expect(baseElement.style.getPropertyValue('overflow')).toBe('')
    fireEvent.click(screen.getByText('Show'))
    const modal = screen.getByTestId(dataTestId)
    expect(modal).toBeDefined()
    expect(baseElement.style.getPropertyValue('overflow')).toBe('hidden')
  })

What you did:

I test the modal component. When a modal has appeared, it should block the body and prevent the user's scroll behavior.

What happened:

After upgrading to @testing-library/react up to 12.1.2 from 11.1.0, I noticed that typing for the baseElement was changed in the 11.12.5.
And I received such error:
Property 'style' does not exist on type 'Element'.

Reproduction:

Try to get some HTML attributes from the baseElement

Problem description:

Previously render returned baseElement as HTMLElement, but now it returns it as Element.

Suggested solution:

Provide examples in the documentation or make flexible types

Metadata

Metadata

Assignees

No one assigned

    Labels

    TypeScriptRelated to TypeScript. Note: only certain maintainers handle TypeScript labeled issues.bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions