Skip to main content

Command Palette

Search for a command to run...

Testing library (React): Selecting text in multiple HTML elements

Updated
1 min read
F

React, Django and SQL developer at Forma.ai

<h3 data-testid="hello-header">Hello <strong>World</strong></h3>

*ByRole

screen.getByRole('heading', { name: 'Hello World' });

or.toHaveTextContent

expect(screen.getByTestId('hello-header')).toHaveTextContent('Hello World');