What do you think about providing Cypress and RTL test selector functions along side your components?

This page summarizes the projects mentioned and recommended in the original post on reddit.com/r/reactjs

Our great sponsors
  • Sonar - Write Clean JavaScript Code. Always.
  • InfluxDB - Build time-series-based applications quickly and at scale.
  • Scout APM - Truly a developer’s best friend
  • Zigi - Workflow assistant built for devs & their teams
  • Grafana

    The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.

    At Grafana we have a separate selectors package, which is basically what you're describing - a collection of selectors used in tests to match elements. The selectors are assigned via `aria-label` (old approach) or `data-testid` (new way) attributes. However, they are mostly used in Cypress e2e tests and not so much in RTL tests (altho that is possible too). I'd advice against using this for RTL unit tests in most cases because while this seems more convenient, you're losing a lot of the advantages of RTL. As one example, when you do `screen.getByRole({'button', {name: 'Submit'})`, you're also testing that your button is accessible to screen readers, if you're unable to match your button with this query (or a similar one) then most likely smth is wrong with your button.

  • Sonar

    Write Clean JavaScript Code. Always.. Sonar helps you commit clean code every time. With over 300 unique rules to find JavaScript bugs, code smells & vulnerabilities, Sonar finds the issues while you focus on the work.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts