callstack / react-native-testing-library

🦉 Simple and complete React Native testing utilities that encourage good testing practices.
https://callstack.github.io/react-native-testing-library/
MIT License
3.1k stars 273 forks source link

RFC: readability vs RTL compatibility in API naming #1194

Closed mdjastrzebski closed 2 years ago

mdjastrzebski commented 2 years ago

RNTL is modelled after RTL, as one of our unstated goals we strive to reimplement RTL for React Native platform, expose familiar features and APIs while accounting for platform differences.

So far we have been reasonably successful with this approach as it delivered familiar and well thought out API. However recently, when we started to implement A11y-related features I’ve found that some of them are somewhat confusingly named:

I think readability of our code could be improved by renaming these in a following way:

Note: the change is only about the naming, the arguments or behaviour do not change.

Such renaming would however break our naming compatibility with RTL.

I see couple of options how we could approach that:

  1. Keep RTL naming
  2. Rename them
  3. Expose both names: promote the readable name as primary, while allowing RTL-compatible name as a secondary option.

I think we should consider using 3rd option, as it gives us both more explicit and readable code while catering for people with RTL background.

@thymikee @AugustinLF @pierrezimmermannbam @MattAgn What do you think?

AugustinLF commented 2 years ago

I vote for the third solution. Or even better, suggest RTL to change :) I agree that we need better name, and RTL's naming shouldn't be the lowest denominator. However having the same names is very important

pierrezimmermannbam commented 2 years ago

I agree with @AugustinLF , the naming hidden is very confusing to me so I think it should change so I'm not in favor of the first option and keeping compatibility with RTL is also very important so having both names seems like the better option

MattAgn commented 2 years ago

I agree with the third option as well, even though I've been working on the hidden option for quite some time now, I still have a hard time remembering what hidden:true means. For hidden, I might even go for includeHiddenElements. If we wanted to be super clear, I'd say includeElementsHiddenFromAccessibility or includeElementsHiddenFromA11y but that might be a bit long

AugustinLF commented 2 years ago

IMO the length of the param shouldn't necessarily be a problem. Ideally you want to enable that as a global settings, and only change it when needed, which hopefully should be almost never.

pierrezimmermannbam commented 2 years ago

I agree with both @AugustinLF and @MattAgn on having a name as explicit as possible

mdjastrzebski commented 2 years ago

Thanks for your feedback guys! I will submit a related PR in the upcoming days.

mdjastrzebski commented 2 years ago

isInaccessible alias to isHiddenFromAccessibility merged as #1211.

How should we proceed with hidden renaming? I would opt for includeHidden naming because my only problem with original prop name is that hidden: true or hidden: false does not give a clear whether hidden elements are actually included or not. Changing that to includeHidden: true makes it clear.

Regarding using includeHiddenFromAccessibility, I think it's too verbose, because there is no other type of hidden (e.g. is includeHiddenFromVisibility), and you would still need to understand the function of the option first time you use it, so includeHidden vs includeHiddenFromAccessibility does not save you that learning step.

Re a11y abbreviation: I think we should avoid it, and use full accessibility spelling in the new features, as a11y might be confusing for user who did not meet with accessibility before. Another reference point would be that RN uses full accessibility spelling for all related props.

@thymikee @AugustinLF @pierrezimmermannbam @MattAgn wdyt about naming propositions. Would someone of you like to contribute PR for hidden option alias, after we establish the name.

I think it would be beneficial to release hidden option support together with improved naming, rather than in separate releases.

MattAgn commented 2 years ago

I agree that the most important is to know what hidden true or false means

As for includeHiddenFromAccessibility, I don't think it matters that much if it's verbose, as @AugustinLF said, most of the time, this option will be rarely used in the queries and the global config should be enough. Furthermore, since it will be rarely be used people might go a few month without using it or seeing it in their codebase. In that case, I think it's best to have a name as clear as possible to help them remember easily what it truly means when they need it.

For a11y VS accessibility and for the release plan, completely agree with you.

I'd be glad to take on the issue and implement the new naming we choose :)

MattAgn commented 2 years ago

For the implementation, here are some of my thoughts and questions (if we were to go with includeHidden for instance):

What do you think?

mdjastrzebski commented 2 years ago

@MattAgn Pls go ahead the PR, I will release RNTL after merging that 🚢

I think we should not complicate things and we should assume that if both options are present then the preferred one (includeHidden) takes precedence over alias one (hidden).

Re naming, let's seen in a PR how the use cases in our tests and doc read with shorter (includeHidden) and/or longer version (includeHiddenFromAccessibility). Maybe that will help us with the naming decision.

MattAgn commented 2 years ago

Alright I'm on it