2

In the React Testing Library tests, I'd like to use the translation library instead of direct strings in the default language. In the documentation, there is information that it can be achieved by using:

const buttonText = getNodeText(<FormattedMessage id="buttonText" defaultMessage="Hello Button" />);

Did anyone try this with a success? When I'm trying to run this code I'm getting the error:

node.matches is not a function

When you check the getNodeText() arguments, it expects HTMLElement, so it seems it's not supposed to work in the way presented in the example. Do you have other ways, how to test components with React Intl without hardcoding text?

Link to the documentation: https://testing-library.com/docs/example-react-intl#translated-components-testing-stategy

0 Answers0