testing-library / dom-testing-library

🐙 Simple and complete DOM testing utilities that encourage good testing practices.
https://testing-library.com/dom
MIT License
3.25k stars 460 forks source link

Highlight non-breaking whitespace in getByRole failure message #1314

Open ckundo opened 1 month ago

ckundo commented 1 month ago

When using getByRole, represent non-breaking whitespace in failure output as  , so that it's easier to diagnose the distinguish between " " and  . This would be in the list below "here are the accessible roles" under the "name" output.

Motivation: Non-breaking whitespace is not collapsed into " " in the accname calculation. This is correct according to the ARIA spec, but is tricky to debug getByRole failures related to usage of non-breaking whitespace. See also #904

Alternatives considered

We considered a custom helper to automatically collapse whitespace, but that is harder to maintain and discover than having the behavior in the core library. Further, it does not actually represent end-user experience since the browser does not perform this collapsing automatically.