-
Notifications
You must be signed in to change notification settings - Fork 58
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
Consider removing testing-library/no-node-access lint rule #847
Comments
I guess the question also is if we need to check these things in the test? |
My feeling is that we do. Because Vanilla defines specific classes and elements (with specific orders) we need to catch any regressions that would result in a broken UI. |
True. While it seems agains the principles of RTL, we not only want to test how user interacts with component, but if the component aligns with Vanilla (HTML structure and class names). I started reviewing some of the migration PRs and there are couple of aspects related to that. 1. Accessing root element of the componentIn some cases we want to access root element of the component - to test a snapshot, to check if it has class names, etc. In current PRs it seems we try to use proper RTL selectors via role. It works in some cases (button), but doesn't in others. Selecting by the "group" role, because root element is a @petermakowski suggested using 2. SnapshotsOn one hand snapshot tests seem to fit into testing compatibility with Vanilla - they exactly check the structure of HTML and class names. So while technically the test "works" - it fails when React structure changes - I'm not sure if it serves the purpose. Because we will quite likely just regenerate the snapshot to make it pass rather than check and notice why it doesn't pass. So, do we need snapshot testing? Or should we more explicitly test for some elements/classnames in the code? 3. Dropping
|
That would be fine, we'd probably also want to disable the
We've been moving away from snapshots in MAAS, particularly as with RTL they become a full snapshot of the tree. My feeling is that specific tests for elements/classnames are generally more useful. Having said that the snapshots do catch regressions when a change results in an unexpected diff in the snapshot (e.g. doing a refactor that should result in the same HTML). I think generally for our apps we probably don't need snapshots, but part of me is leaning towards keeping these in react-components as I think we generally want to be a bit more pedantic as any breakage in react-components could break all our sites, but I don't feel too strongly either way.
I guess the other side of this is that we don't want to discourage testing these components properly. It's not actually wrong to check the DOM structure or classes but having to override the lint rule makes it feel like you're doing something naughty. |
Triage: seems that for now we are able to handle it as is. For the new architecture of Vanilla we should revisit the decision on how we want to write tests and what level of access to give in tests. |
To build a component library around Vanilla we really care about the class names, visual elements, node order etc. not just the accessible labels and roles
To do this we often need to access the DOM directly so a lot of tests require disabling
testing-library/no-node-access
so possibly we should just disable that lint rule (though I could be overlooking some way of checking these things with RTL).The text was updated successfully, but these errors were encountered: