I'm trying to find the best practice to test textContent for a div element here, using react testing library.
Say I'd like to test this simple react component to see if {props.text} is rendered properly on the HTML DOM.
const Simple = props => (
<>
<div> {props.text} </div>
<div> test text </div>
</>
);
I've tried to use getByText, then test expect(getByText('text passed as prop')).toBeDefined() but it didn't seem to work properly.
It must be much easier if I add a className or id for the first <div /> then probably I can just go for querySelector, but what if I didn't want to add any HTML attribute here? How can I locate this element properly?
Is there any solution to find the first element that has no attribute and test its inner text?