Many tests in our codebase test for the existence of an element by checking if the node contains a string of text.
This is fine to test whether a component renders a string of text based on properties or as a result of in-component calculations, but not just to test whether an element exists.
This is not good practice for several reasons:
- the string to test for is not defined in the test itself/not part of the test set-up
- the text contained might change anytime, the test would fail although the functionality is actually fine
- as a result, tests are extremely brittle
Instead, we should test for the existence of the node itself by an appropriate selector (which can be used specifically for this purpose, but using the main class name as derived formt he component name is good enough: