Here’s an example of a Jest test case that searches for a specific text within a rendered component:
In this example, we import the render
function from the @testing-library/react
package and our component MyComponent
. We then use the getByText
function from the render
output to search for the text 'Hello, world!' within the rendered component.
Finally, we use the Jest expect
function to assert that the specific text is present in the rendered component by using the toBeInTheDocument
matcher.