Skip to content
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

Requesting review of Ember test selectors (data-test) excerpt from the testing guide #1855

Open
OmShiv opened this issue Oct 20, 2022 · 0 comments

Comments

@OmShiv
Copy link

OmShiv commented Oct 20, 2022

I am interested to know how I can request a change of these excerpts from the Testing guides, and whom I can reach for the following concerns. Kindly guide.

excerpt

While you can use CSS classes as selectors, a best practice for testing is to <strong>separate the concerns between styling and testing</strong>. Class names and DOM structure change over time—for the better—by you, your team, and addon developers. If you rely on CSS classes, your tests will break and need a significant rewrite.

Class names and DOM structure change over time—for the better—by you, your team, and addon developers. If you rely on CSS classes, your tests will break and need a significant rewrite

concern

When DOM changes are unavoidable, it is natural that the data-test selectors will also need to be moved, and refactored. How does using data-test selectors provide any perceivable/measurable value?

excerpt

[Ember Test Selectors](https://github.com/simplabs/ember-test-selectors) is an addon that helps you **write tests that are more resilient to DOM changes**. You use `data-test-*` attributes to mark the elements that will be used in your tests. The addon works with QUnit DOM and helpers from [@ember/test-helpers](https://github.com/emberjs/ember-test-helpers/). It also removes the `data-test-*` attributes in the production build.

If you rely on CSS classes, your tests will break and need a significant rewrite.

concern

Don’t we want this? Classes are part of the user experience, so tests should break if they change. If not, then this concern is also applicable to data-test selectors. That is, when you change the DOM you also need to move/change data-test selectors without which the tests will break in a similar fashion and will need rewrite.

In that case, data-test selector becomes useful exactly in this case when you have an element

  • that can change the type (span ➞ div ➞ li, etc),
  • can change the class,
  • but still, needs to play the same role? This is not common and is sometimes unrealistic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant