Skip to content

Commit 6afa333

Browse files
Merge pull request #89 from Workiva/r18-workaround-css-escape-id
FED-3909 [hasDescription matcher] escape special characters in ids
2 parents abcb884 + b9f2c4c commit 6afa333

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# React Testing Library Changelog
22

3+
## 3.1.1
4+
* [#89](https://github.com/Workiva/react_testing_library/pull/89) Escape special characters in ids in `hasDescription` matcher
5+
36
## 3.1.0
47
* [#86](https://github.com/Workiva/react_testing_library/pull/86) Add Dart bindings for React `act`
58

lib/src/matchers/jest_dom/has_description.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class _HasDescription extends CustomMatcher with ElementTextContentMatcherMixin
141141

142142
final elementsWithDescriptions = <Element>[];
143143
_idsOfElementsThatDescribe(item)?.forEach((id) {
144-
final elWithDesc = querySelector('#$id');
144+
final elWithDesc = querySelector('#${Css.escape(id)}');
145145
if (elWithDesc != null) {
146146
elementsWithDescriptions.add(elWithDesc);
147147
}

test/unit/dom/matchers/has_description_test.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,16 @@ void main() {
3131
{},
3232
react.button({
3333
'aria-label': 'Close',
34-
'aria-describedby': 'description-close',
34+
// Use a special character to verify that it is escaped correctly in hasDescription.
35+
'aria-describedby': 'r:description-close',
3536
}, 'X'),
3637
react.button({
3738
'aria-label': 'Has Multiple Descriptions',
38-
'aria-describedby': 'description-close some-other-description',
39+
'aria-describedby': 'r:description-close some-other-description',
3940
}, 'X'),
4041
react.button({}, 'Delete'),
4142
react.button({'aria-describedby': 'not-found'}, 'Has id not found'),
42-
react.div({'id': 'description-close'}, 'Closing will discard any changes'),
43+
react.div({'id': 'r:description-close'}, 'Closing will discard any changes'),
4344
react.div({'id': 'some-other-description'}, 'Some other description'),
4445
));
4546
});

0 commit comments

Comments
 (0)