-
Notifications
You must be signed in to change notification settings - Fork 665
Description
As suggested here, I'm opening up this issue to suggest the addition of methods that simplify the usage of test data attributes.
Using data-testid
(or data-test
, the name specifics is not the goal of the issue) might become one of the suggested ways to query components in VTU. In short, with a test-related data attribute we make the relationship between test and code under test resilient and more explicit (among other benefits).
What problem does this feature solve?
However, right now it is quite hard to type, prone to errors, and even slow to read:
wrapper.find('[data-testid="fooBar"]')
Not to mention how this would look if we needed to add some variables and backticks to the mix.
What does the proposed API look like?
I see two main options to avoid this problem, and thus make the recommended way a bit more comfortable:
-
To provide a different method:
findByTestId('fooBar')
.
Is easy to grasp and self-explanatory, but splits the find() API in two. This is the approach used in the Testing Library family (source). -
To make data-testid the default behavior for
find
, so thatfind('fooBar')
becomesfind('[data-testid="fooBar"]')
internally in VTU.
This would mean thatfind('button')
would no longer return a button element, but rather the element withdata-testid="button"
. This might be undesirable.
Thoughts?