-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: adjust ByTestId misleading warnings; add guidelines about accessibilityHint #542
Conversation
IMO I would consider rewording these notes rather than removing them. Please compare to RTL's note:
Source: https://testing-library.com/docs/dom-testing-library/api-queries#bytestid Maybe we can add info that:
Wdyt? |
On iOS, all accessibility properties are used by the accessibility system to present to the user, so all text in those comprises of user-facing, localized strings. From our experience, such strings are not a good fit for matching views:
The exception to this are accessibility identifiers, which are not used by the OS for anything other than matching. From experience, using those to give a unique across the app identifier to user elements is the best way to match elements uniquely. We understand that this may not be practical at all times, but we do try to steer our users (internally in the company and community) toward such an approach first, and then try different things if this is not possible. |
At any rate, I don't think any guideline should be advising people to outright avoid test identifiers. |
@LeoNatan I do not advise against using test ids for end to end tests, if they are the most viable solution then fine. I do however believe that for RNTL integration tests, test ids are kind of escape hatches, you should use them when other methods of finding elements are not good enough. And indeed there are many cases for using test ids: e.g. container elements, screens, etc but usually not text inputs, buttons, etc. My reasoning follows from React Testing Library guiding principle:
The reason why using Addressing your points:
Regarding replacing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I think the new notes are more explanatory then before.
That's brilliant! |
Summary
This PR is inspired by the discussion happening here wix/Detox#2313.
There's no need for us to recommend users whether they should avoid
ByTestId
queries or not. In fact, I noticed that developers tend to take our recommendations seriously and, maybe due to lack of better ideas, useaccessibilityHint
the same way astestID
, which is even worse for the users, as they get some rubbish developer metadata instead of actual feedback.For reference, here's Apple guideline on how and when
accessibilityHint
should be used: https://developer.apple.com/documentation/objectivec/nsobject/1615093-accessibilityhint. I've adjusted our example accordingly, so it doesn't spread misleading information.Test plan
Docs