React Testing Examples

react-testing-library
GitHubAbout
All examples

The component renders variable text based on a string prop. We test that the component renders the value of the passed prop.

test.js
it('renders personalized greeting', async () => {
// Render new instance in every test to prevent leaking state
const { getByText } = render(<HelloMessage name="Satoshi" />);
await waitForElement(() => getByText(/hello Satoshi/i));
});
it('renders personalized greeting', async () => {
  // Render new instance in every test to prevent leaking state
  const { getByText } = render(<HelloMessage name="Satoshi" />);

  await waitForElement(() => getByText(/hello Satoshi/i));
});