From 52f06ef2a63c4f2e80ad3eca75dd107eb21f5ba2 Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Fri, 10 Dec 2021 09:18:40 -0700 Subject: [PATCH 1/2] Fix test ID queries not properly escaping RegExps --- lib/src/dom/queries/by_testid.dart | 4 +++- test/unit/dom/queries/by_testid_test.dart | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/src/dom/queries/by_testid.dart b/lib/src/dom/queries/by_testid.dart index 51dc5340..e04aee2d 100644 --- a/lib/src/dom/queries/by_testid.dart +++ b/lib/src/dom/queries/by_testid.dart @@ -445,7 +445,9 @@ external List< /*Element*/ dynamic> _jsQueryAllByTestId( dynamic _convertTestIdStringToRegExp(dynamic testId, {bool exact = true}) { if (testId is! String) return TextMatch.toJs(testId); - final testIdMatcher = exact ? RegExp('(\\s|^)$testId(\\s|\$)') : RegExp('(.?)$testId(.?)', caseSensitive: false); + final testIdMatcher = exact + ? RegExp('(\\s|^)${RegExp.escape(testId as String)}(\\s|\$)') + : RegExp('(.?)${RegExp.escape(testId as String)}(.?)', caseSensitive: false); return TextMatch.toJs(testIdMatcher); } diff --git a/test/unit/dom/queries/by_testid_test.dart b/test/unit/dom/queries/by_testid_test.dart index c05a8cb0..22e84fbf 100644 --- a/test/unit/dom/queries/by_testid_test.dart +++ b/test/unit/dom/queries/by_testid_test.dart @@ -189,6 +189,16 @@ void main() { }); }); + test( + 'works when test IDs contain regular expression syntax' + ' (by properly escaping the test ID when incorporating it into a RegExp)', () { + final view = rtl.render(react.span({ + 'data-test-id': 'testId(1)', + }) as ReactElement); + + expect(view.getByTestId('testId(1)'), isA()); + }); + group('with the "exact: false" argument', () { group('getByTestId', () { test('[non-exact string match]', () { @@ -255,6 +265,16 @@ void main() { expect(await view.findAllByTestId('estid-2', exact: false), hasLength(2)); }); }); + + test( + 'works when test IDs contain regular expression syntax' + ' (by properly escaping the test ID when incorporating it into a RegExp)', () { + final view = rtl.render(react.span({ + 'data-test-id': 'testId(1)', + }) as ReactElement); + + expect(view.getByTestId('estId(1)', exact: false), isA()); + }); }); }); From d3c235ad6305457a04cc59cc194ac54b91028083 Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Fri, 10 Dec 2021 09:49:54 -0700 Subject: [PATCH 2/2] Attempt to fix timeouts --- test/unit/dom/wait_for_test.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/unit/dom/wait_for_test.dart b/test/unit/dom/wait_for_test.dart index 551106bd..dd641ed0 100644 --- a/test/unit/dom/wait_for_test.dart +++ b/test/unit/dom/wait_for_test.dart @@ -456,5 +456,6 @@ void main() { }, timeout: asyncQueryTestTimeout); }); }); - }); + // Attempt to fix flaky timeout failures in CI + }, tags: 'run-alone'); }