Home > @lynx-js/react/testing-library > render

render() function

Render into the page. It should be used with cleanup.

Signature:

export function render<Q extends Queries>(
  ui: ComponentChild,
  options?: RenderOptions<Q>,
): RenderResult<Q>;

Parameters

Parameter Type Description
ui ComponentChild
options RenderOptions<Q> (Optional)

Returns:

RenderResult<Q>

Example

import { render} from '@lynx-js/react/testing-library'

const WrapperComponent = ({ children }) => (
    <view data-testid='wrapper'>{children}</view>
);
const Comp = () => {
  return <view data-testid='inner' style="background-color: yellow;" />;
};
const { container, getByTestId } = render(<Comp />, {
  wrapper: WrapperComponent,
});
expect(getByTestId('wrapper')).toBeInTheDocument();
expect(container.firstChild).toMatchInlineSnapshot(`
  <view
    data-testid="wrapper"
  >
    <view
      data-testid="inner"
      style="background-color: yellow;"
    />
  </view>
`);
Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.