getComponentRootDomByTestId function

Element? getComponentRootDomByTestId(
  1. dynamic root,
  2. String value, {
  3. String key = defaultTestIdKey,
})

Returns the Element of the first descendant of root that has its key prop value set to value.

Returns null if no descendant has its key prop value set to value.

Example:

// Render method for `Test` `UiFactory`:
render() {
  return (Dom.div()..addTestId('outer'))(
    (Dom.div()
      ..addProps(copyUnconsumedProps())
      ..addTestId('inner')
    )()
  );
}

// Within a test:
var renderedInstance = render((Test()..addTestId('value'))());

// Will result in the following DOM:
<div data-test-id="outer">
  <div data-test-id="inner value">
  </div>
</div>

getComponentRootDomByTestId(renderedInstance, 'value'); // returns the `outer` `<div>`

Related: queryByTestId.

Implementation

Element? getComponentRootDomByTestId(dynamic root, String value, {String key = defaultTestIdKey}) {
  return findDomNode(getByTestId(root, value, key: key));
}