Closed
Description
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:
- Validate that it is invoked on a host element
- Check if given element contains any host child elements (using
getHostChildren
fn)
Each matcher should have a fairly comprehensive test suite.
Links
toBeEmptyDOMElement
matcher code from Jest DOM: https://github.com/testing-library/jest-dom/blob/main/src/to-be-empty-dom-element.jstoBeEmptyElement
implementation for Jest Native: https://github.com/testing-library/jest-native/blob/main/src/to-be-empty-element.ts