How do I make expect(stuff).toHaveTextContent(text) pass only when the text matches exactly?
.toHaveTextContent("1") counts as a match if the text I'm testing is "100"
How do I make expect(stuff).toHaveTextContent(text) pass only when the text matches exactly?
.toHaveTextContent("1") counts as a match if the text I'm testing is "100"
Get the the text using innerHTML
const element = await waitFor(() => document.querySelector('<YOUR_QUERY>'));
expect(element.innerHTML).toEqual('100')
Use getByText like so,
const { getByText } = render(<YourComponent />)
expect(getByText('text you\'re looking for')).beInTheDocument()
This assumes it will be there, so if there's a chance it won't be, use queryByText.
Use a regex instead expect(stuff).toHaveTextContent(/^100$/); if you want to match exactly.
As written in the doc (https://github.com/testing-library/jest-dom#tohavetextcontent), it will (just) "check whether the given node has a text content or not"