[React Testing] Use React Testing Library’s Wrapper Option to Simplify using rerender

We have a bit of repetition in our rerender calls here and it would be nice if we could avoid that. Let’s use the wrapper option for React Testing Library so we can avoid the repetition in our rerender calls.

Previous:

  const { rerender, getByRole, getByText, queryByText, queryByRole } = render(
    <ErrorBoundary>
      <Bomb />
    </ErrorBoundary>,
  )

  rerender(
    <ErrorBoundary>
      <Bomb shouldThrow={true} />
    </ErrorBoundary>,
  )

Now:

  const { rerender, getByRole, getByText, queryByText, queryByRole } = render(
    <Bomb />,
    { wrapper: ErrorBoundary },
  )

  rerender(<Bomb shouldThrow={true} />)

猜你喜欢

转载自www.cnblogs.com/Answer1215/p/12814662.html