...
/Use data-testid Attributes to Combat Brittle Tests
Use data-testid Attributes to Combat Brittle Tests
Learn how to deal with brittle tests in our Rails application.
We'll cover the following...
We'll cover the following...
The tags used in our view are currently semantically correct, and thus, our tests can safely rely on that. However, these semantics might change without affecting the way the page actually works. Suppose we want a new message, “Widget Information,” on the page as the most important thing. That means our widget name should no longer be an <h1>, but instead an <h2>.
Here’s the change to update the view:
This change will break our tests even though the change didn’t affect the functionality of the feature:
We can see what’s broken, but the best way to fix it is not clear. If we change the tag name used in ...