[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} />)

 

posted @ 2020-05-01 20:28  Zhentiw  阅读(172)  评论(0编辑  收藏  举报