renderShallow function

ReactElement renderShallow(
  1. ReactElement instance, {
  2. bool autoTearDown = true,
  3. Callback? autoTearDownCallback,
})

Shallow-renders a component using react_test_utils.ReactShallowRenderer.

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

See: facebook.github.io/react/docs/test-utils.html#shallow-rendering.

Implementation

ReactElement renderShallow(ReactElement instance, {bool autoTearDown = true, Callback? autoTearDownCallback}) {
  var renderer = react_test_utils.createRenderer();
  if (autoTearDown) {
    addTearDown(() {
      renderer.unmount();
      if (autoTearDownCallback != null) autoTearDownCallback();
    });
  }
  renderer.render(instance);
  return renderer.getRenderOutput();
}