From 063dbcc7e6ffc64dd4e97bb28f849f3d40eeb61e Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Wed, 11 Jun 2025 16:01:24 -0700 Subject: [PATCH 1/3] Add test --- test/unit/dom/matchers/has_description_test.dart | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/unit/dom/matchers/has_description_test.dart b/test/unit/dom/matchers/has_description_test.dart index b6bf7d7d..53104441 100644 --- a/test/unit/dom/matchers/has_description_test.dart +++ b/test/unit/dom/matchers/has_description_test.dart @@ -31,15 +31,16 @@ void main() { {}, react.button({ 'aria-label': 'Close', - 'aria-describedby': 'description-close', + // Use a special character to verify that it is escaped correctly in hasDescription. + 'aria-describedby': 'r:description-close', }, 'X'), react.button({ 'aria-label': 'Has Multiple Descriptions', - 'aria-describedby': 'description-close some-other-description', + 'aria-describedby': 'r:description-close some-other-description', }, 'X'), react.button({}, 'Delete'), react.button({'aria-describedby': 'not-found'}, 'Has id not found'), - react.div({'id': 'description-close'}, 'Closing will discard any changes'), + react.div({'id': 'r:description-close'}, 'Closing will discard any changes'), react.div({'id': 'some-other-description'}, 'Some other description'), )); }); From 1aa9cf5a511583293ebc1dd506256aa031c058a2 Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Wed, 11 Jun 2025 16:05:21 -0700 Subject: [PATCH 2/3] Escape id --- lib/src/matchers/jest_dom/has_description.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/matchers/jest_dom/has_description.dart b/lib/src/matchers/jest_dom/has_description.dart index 8402f698..3d8be7e1 100644 --- a/lib/src/matchers/jest_dom/has_description.dart +++ b/lib/src/matchers/jest_dom/has_description.dart @@ -141,7 +141,7 @@ class _HasDescription extends CustomMatcher with ElementTextContentMatcherMixin final elementsWithDescriptions = []; _idsOfElementsThatDescribe(item)?.forEach((id) { - final elWithDesc = querySelector('#$id'); + final elWithDesc = querySelector('#${Css.escape(id)}'); if (elWithDesc != null) { elementsWithDescriptions.add(elWithDesc); } From b9f2c4c231ae37937f3e23c4161d312db99c10ab Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Mon, 16 Jun 2025 09:51:14 -0700 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b96e551..04caec5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # React Testing Library Changelog +## 3.1.1 +* [#89](https://github.com/Workiva/react_testing_library/pull/89) Escape special characters in ids in `hasDescription` matcher + ## 3.1.0 * [#86](https://github.com/Workiva/react_testing_library/pull/86) Add Dart bindings for React `act`