Skip to content

toBeVisible should imply toBeInTheDocument #338

@calebeby

Description

@calebeby

Describe the feature you'd like:

I think that it would make sense for toBeVisible to perform, in addition to its CSS-based checks, checks that confirm that the element is in the document.

test('toBeVisible with removed element', () => {
  document.body.innerHTML = "<div id='el'>content</div>"
  const el = document.getElementById('el')
  expect(el).toBeVisible()
  el.remove()
  expect(el).not.toBeVisible() // this line fails, element is "visible"
})

If we think about it from a CSS standpoint, yes, there is no CSS that is preventing the element from being visible. But from the user's perspective, the element is definitely not visible. For this reason I think it makes sense to change the behavior of .toBeVisible to include the checks from .toBeInTheDocument.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions