I'm trying to write a test for the presence of text after a certain value in my html document:
<span>Dog facts: something</span>
I want to test for the presence of text after the pattern "Dog facts:" to not be null
It should be noted the value after Dog facts: changes so I can't assert on a specific value I just need to make sure that there exists text after the colon.
I am not sure if regex is what I want but I tried doing this:
test('renders dog facts', () => {
render(<App />);
const linkElement = screen.getByText(/Dog facts:/i);
expect(linkElement).toBeInTheDocument();
});
but this always returns true no matter whats after the colon
If you want to only match for a letter after the dog facts you can use this.
/Dog Facts: \w/g