renderAndGetDom function

Element? renderAndGetDom(
  1. dynamic component, {
  2. bool autoTearDown = true,
  3. Callback? autoTearDownCallback,
})

Renders a React component or builder into a detached node and returns the associated DOM node.

By default the rendered instance will be unmounted after the current test, to prevent this behavior set autoTearDown to false.

If component is a function component, calling renderAndGetDom will throw a StateError.

See TestJacket.getNode for more information about this limitation.

Implementation

Element? renderAndGetDom(dynamic component, {bool autoTearDown = true, Callback? autoTearDownCallback}) {
  final renderedInstance = render(component, autoTearDown: autoTearDown, autoTearDownCallback: autoTearDownCallback);

  if (!react_test_utils.isCompositeComponent(renderedInstance) && !react_test_utils.isDOMComponent(renderedInstance)) {
    throw StateError(
      'renderAndGetDom() is only supported when the rendered object is a DOM or composite (class based) component.');
  }

  return findDomNode(renderedInstance);
}