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` 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); } 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'), )); });