Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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

import React from 'react';
import { render, waitForElement } from 'react-testing-library';
import { HelloMessage } from 'shared/components/HelloMessage';

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));
});
Source by react-testing-examples.com #
 
PREVIOUS NEXT
Tagged: #Text #prop #rendered #The #component #renders #variable #text #based #string #We #test #component #renders #passed
ADD COMMENT
Topic
Name
7+2 =