Skip to content

feature: implement toBeEmptyElement Jest matcher #1459

Closed
@mdjastrzebski

Description

@mdjastrzebski

Describe the Feature

toBeEmptyDOMElement is a Jest DOM matcher that asserts the visibility of given element by inspecting whether it contains any child elements.

Adapting it to our case it would assert that given host element does not contain any host children elements. It might contain some composite elements as long as these do not have host descendants. We already have function for getting host children of given element (getHostChildren) so that should be relatively straightforward.

Possible Implementations

Proposed API:

export function toBeEmptyElement(
  this: jest.MatcherContext,
  element: ReactTestInstance
)

The matcher should:

  1. Validate that it is invoked on a host element
  2. Check if given element contains any host child elements (using getHostChildren fn)

Each matcher should have a fairly comprehensive test suite.

Links

Related Issues

#1454

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions