From 65d968a5e92d805dc36b59c1a659eb39724100ca Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Wed, 14 Jun 2023 13:05:43 -0500 Subject: [PATCH 01/31] Remove @dart 2.7 comments --- lib/dom/accessibility.dart | 1 - lib/dom/async.dart | 1 - lib/dom/configure.dart | 1 - lib/dom/debugging.dart | 1 - lib/dom/events.dart | 1 - lib/dom/queries.dart | 1 - lib/matchers.dart | 1 - lib/react/react.dart | 1 - lib/react_testing_library.dart | 1 - lib/src/dom/accessibility_helpers.dart | 1 - lib/src/dom/async/types.dart | 1 - lib/src/dom/async/wait_for.dart | 1 - lib/src/dom/config/configure.dart | 1 - lib/src/dom/config/types.dart | 1 - lib/src/dom/fire_event.dart | 1 - lib/src/dom/matches/get_default_normalizer.dart | 1 - lib/src/dom/matches/types.dart | 1 - lib/src/dom/pretty_dom.dart | 1 - lib/src/dom/queries/by_alt_text.dart | 1 - lib/src/dom/queries/by_display_value.dart | 1 - lib/src/dom/queries/by_label_text.dart | 1 - lib/src/dom/queries/by_placeholder_text.dart | 1 - lib/src/dom/queries/by_role.dart | 1 - lib/src/dom/queries/by_testid.dart | 1 - lib/src/dom/queries/by_text.dart | 1 - lib/src/dom/queries/by_title.dart | 1 - lib/src/dom/queries/interface.dart | 1 - lib/src/dom/scoped_queries.dart | 1 - lib/src/dom/top_level_queries.dart | 1 - lib/src/dom/within.dart | 1 - lib/src/matchers/jest_dom.dart | 1 - lib/src/matchers/jest_dom/contains_element.dart | 1 - lib/src/matchers/jest_dom/css_class_matchers.dart | 1 - lib/src/matchers/jest_dom/has_attribute.dart | 1 - lib/src/matchers/jest_dom/has_description.dart | 1 - lib/src/matchers/jest_dom/has_form_values.dart | 1 - lib/src/matchers/jest_dom/has_styles.dart | 1 - lib/src/matchers/jest_dom/has_text_content.dart | 1 - lib/src/matchers/jest_dom/has_value.dart | 1 - lib/src/matchers/jest_dom/is_checked.dart | 1 - lib/src/matchers/jest_dom/is_disabled.dart | 1 - lib/src/matchers/jest_dom/is_empty_dom_element.dart | 1 - lib/src/matchers/jest_dom/is_focused.dart | 1 - lib/src/matchers/jest_dom/is_in_the_document.dart | 1 - lib/src/matchers/jest_dom/is_partially_checked.dart | 1 - lib/src/matchers/jest_dom/util/constants.dart | 1 - .../jest_dom/util/element_text_content_matcher_mixin.dart | 1 - lib/src/matchers/jest_dom/util/get_value_of.dart | 1 - lib/src/react/render/render.dart | 1 - lib/src/react/render/types.dart | 1 - lib/src/user_event/special_chars.dart | 1 - lib/src/user_event/user_event.dart | 1 - lib/src/util/console_log_formatter.dart | 1 - lib/src/util/console_log_utils.dart | 1 - lib/src/util/error_message_utils.dart | 1 - lib/src/util/event_handler_error_catcher.dart | 1 - lib/src/util/is_or_contains.dart | 1 - lib/src/util/js_utils.dart | 1 - lib/user_event.dart | 1 - pubspec.yaml | 6 ++++++ test/unit/console_log_utils_test.dart | 1 - test/unit/dom/accessibility_helpers_test.dart | 1 - test/unit/dom/configure_test.dart | 1 - test/unit/dom/fire_event_test.dart | 1 - test/unit/dom/matchers/contains_element_test.dart | 1 - test/unit/dom/matchers/css_class_matchers_test.dart | 1 - test/unit/dom/matchers/has_attribute_test.dart | 1 - test/unit/dom/matchers/has_description_test.dart | 1 - test/unit/dom/matchers/has_form_values_test.dart | 1 - test/unit/dom/matchers/has_styles_test.dart | 1 - test/unit/dom/matchers/has_text_content_test.dart | 1 - test/unit/dom/matchers/has_value_test.dart | 1 - test/unit/dom/matchers/is_checked_test.dart | 1 - test/unit/dom/matchers/is_disabled_test.dart | 1 - test/unit/dom/matchers/is_empty_dom_element_test.dart | 1 - test/unit/dom/matchers/is_focused_test.dart | 1 - test/unit/dom/matchers/is_in_the_document_test.dart | 1 - test/unit/dom/matchers/is_partially_checked_test.dart | 1 - test/unit/dom/pretty_dom_test.dart | 1 - test/unit/dom/queries/by_label_text_test.dart | 1 - test/unit/dom/queries/by_role_test.dart | 1 - test/unit/dom/queries/by_testid_test.dart | 1 - test/unit/dom/queries/by_text_test.dart | 1 - test/unit/dom/queries/shared/scoped_queries_tests.dart | 1 - .../dom/queries/shared/text_match_type_parsing_tests.dart | 1 - test/unit/dom/text_match_test.dart | 1 - test/unit/dom/top_level_queries_test.dart | 1 - test/unit/dom/wait_for_test.dart | 1 - test/unit/dom/within_test.dart | 1 - test/unit/react/render_test.dart | 1 - test/unit/user_event/clear_test.dart | 1 - test/unit/user_event/click_test.dart | 1 - test/unit/user_event/hover_test.dart | 1 - test/unit/user_event/paste_test.dart | 1 - test/unit/user_event/select_options_test.dart | 1 - test/unit/user_event/special_chars_test.dart | 1 - test/unit/user_event/tab_test.dart | 1 - test/unit/user_event/type_test.dart | 1 - test/unit/user_event/upload_test.dart | 1 - test/unit/util/constants.dart | 1 - test/unit/util/enums.dart | 1 - test/unit/util/event_handler_error.dart | 1 - test/unit/util/exception.dart | 1 - test/unit/util/init.dart | 1 - test/unit/util/matchers.dart | 1 - test/unit/util/over_react_stubs.dart | 1 - test/unit/util/prints_and_logs_recording.dart | 1 - test/unit/util/rendering.dart | 1 - test/unit/util/shadow_dom.dart | 1 - test/unit/util/string_trimming.dart | 1 - 110 files changed, 6 insertions(+), 109 deletions(-) diff --git a/lib/dom/accessibility.dart b/lib/dom/accessibility.dart index b5d36d02..e46ab8e2 100644 --- a/lib/dom/accessibility.dart +++ b/lib/dom/accessibility.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/dom/async.dart b/lib/dom/async.dart index 556e013c..f8a09d5f 100644 --- a/lib/dom/async.dart +++ b/lib/dom/async.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/dom/configure.dart b/lib/dom/configure.dart index 5edd3916..ecdb1d5e 100644 --- a/lib/dom/configure.dart +++ b/lib/dom/configure.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/dom/debugging.dart b/lib/dom/debugging.dart index 330a8238..64267dfb 100644 --- a/lib/dom/debugging.dart +++ b/lib/dom/debugging.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/dom/events.dart b/lib/dom/events.dart index 3ca83f37..7c6791fe 100644 --- a/lib/dom/events.dart +++ b/lib/dom/events.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/dom/queries.dart b/lib/dom/queries.dart index 97f874ed..8df6c624 100644 --- a/lib/dom/queries.dart +++ b/lib/dom/queries.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/matchers.dart b/lib/matchers.dart index 4421591e..d7c9b61b 100644 --- a/lib/matchers.dart +++ b/lib/matchers.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/react/react.dart b/lib/react/react.dart index b355b50d..f0025338 100644 --- a/lib/react/react.dart +++ b/lib/react/react.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/react_testing_library.dart b/lib/react_testing_library.dart index 46a8d812..270abfb8 100644 --- a/lib/react_testing_library.dart +++ b/lib/react_testing_library.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/dom/accessibility_helpers.dart b/lib/src/dom/accessibility_helpers.dart index 372fc666..7fc31347 100644 --- a/lib/src/dom/accessibility_helpers.dart +++ b/lib/src/dom/accessibility_helpers.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/dom/async/types.dart b/lib/src/dom/async/types.dart index b1a8e955..c9eccba1 100644 --- a/lib/src/dom/async/types.dart +++ b/lib/src/dom/async/types.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/dom/async/wait_for.dart b/lib/src/dom/async/wait_for.dart index 31d2bdb6..199f0ed2 100644 --- a/lib/src/dom/async/wait_for.dart +++ b/lib/src/dom/async/wait_for.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/dom/config/configure.dart b/lib/src/dom/config/configure.dart index c3256a15..108e726f 100644 --- a/lib/src/dom/config/configure.dart +++ b/lib/src/dom/config/configure.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/dom/config/types.dart b/lib/src/dom/config/types.dart index f8efe11d..00b2b3b5 100644 --- a/lib/src/dom/config/types.dart +++ b/lib/src/dom/config/types.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/dom/fire_event.dart b/lib/src/dom/fire_event.dart index bac0a918..27891fc5 100644 --- a/lib/src/dom/fire_event.dart +++ b/lib/src/dom/fire_event.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/dom/matches/get_default_normalizer.dart b/lib/src/dom/matches/get_default_normalizer.dart index ce40fbad..9efcfc1d 100644 --- a/lib/src/dom/matches/get_default_normalizer.dart +++ b/lib/src/dom/matches/get_default_normalizer.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/dom/matches/types.dart b/lib/src/dom/matches/types.dart index 2c92afbc..a903da84 100644 --- a/lib/src/dom/matches/types.dart +++ b/lib/src/dom/matches/types.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/dom/pretty_dom.dart b/lib/src/dom/pretty_dom.dart index 865a9e37..ef505bb3 100644 --- a/lib/src/dom/pretty_dom.dart +++ b/lib/src/dom/pretty_dom.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/dom/queries/by_alt_text.dart b/lib/src/dom/queries/by_alt_text.dart index fff6b21f..11847779 100644 --- a/lib/src/dom/queries/by_alt_text.dart +++ b/lib/src/dom/queries/by_alt_text.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/dom/queries/by_display_value.dart b/lib/src/dom/queries/by_display_value.dart index f05ac668..4ac7d34b 100644 --- a/lib/src/dom/queries/by_display_value.dart +++ b/lib/src/dom/queries/by_display_value.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/dom/queries/by_label_text.dart b/lib/src/dom/queries/by_label_text.dart index 224ce907..1b941228 100644 --- a/lib/src/dom/queries/by_label_text.dart +++ b/lib/src/dom/queries/by_label_text.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/dom/queries/by_placeholder_text.dart b/lib/src/dom/queries/by_placeholder_text.dart index 51dacc8d..eaa5bdc9 100644 --- a/lib/src/dom/queries/by_placeholder_text.dart +++ b/lib/src/dom/queries/by_placeholder_text.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/dom/queries/by_role.dart b/lib/src/dom/queries/by_role.dart index 4df1d0d7..4055dac7 100644 --- a/lib/src/dom/queries/by_role.dart +++ b/lib/src/dom/queries/by_role.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/dom/queries/by_testid.dart b/lib/src/dom/queries/by_testid.dart index e04aee2d..247ee61c 100644 --- a/lib/src/dom/queries/by_testid.dart +++ b/lib/src/dom/queries/by_testid.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/dom/queries/by_text.dart b/lib/src/dom/queries/by_text.dart index 248c6083..54de2afb 100644 --- a/lib/src/dom/queries/by_text.dart +++ b/lib/src/dom/queries/by_text.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/dom/queries/by_title.dart b/lib/src/dom/queries/by_title.dart index d69b2891..a14ffc2e 100644 --- a/lib/src/dom/queries/by_title.dart +++ b/lib/src/dom/queries/by_title.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/dom/queries/interface.dart b/lib/src/dom/queries/interface.dart index b04683ca..4b13cf37 100644 --- a/lib/src/dom/queries/interface.dart +++ b/lib/src/dom/queries/interface.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/dom/scoped_queries.dart b/lib/src/dom/scoped_queries.dart index be1346a9..ebd5f0d8 100644 --- a/lib/src/dom/scoped_queries.dart +++ b/lib/src/dom/scoped_queries.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/dom/top_level_queries.dart b/lib/src/dom/top_level_queries.dart index d45705d3..9df9ffda 100644 --- a/lib/src/dom/top_level_queries.dart +++ b/lib/src/dom/top_level_queries.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/dom/within.dart b/lib/src/dom/within.dart index 578902f2..63b8c268 100644 --- a/lib/src/dom/within.dart +++ b/lib/src/dom/within.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/matchers/jest_dom.dart b/lib/src/matchers/jest_dom.dart index b24b9ac9..63ed80ef 100644 --- a/lib/src/matchers/jest_dom.dart +++ b/lib/src/matchers/jest_dom.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/matchers/jest_dom/contains_element.dart b/lib/src/matchers/jest_dom/contains_element.dart index c4842dbe..898023fd 100644 --- a/lib/src/matchers/jest_dom/contains_element.dart +++ b/lib/src/matchers/jest_dom/contains_element.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/matchers/jest_dom/css_class_matchers.dart b/lib/src/matchers/jest_dom/css_class_matchers.dart index 41d9e8e9..6ebb86b1 100644 --- a/lib/src/matchers/jest_dom/css_class_matchers.dart +++ b/lib/src/matchers/jest_dom/css_class_matchers.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/matchers/jest_dom/has_attribute.dart b/lib/src/matchers/jest_dom/has_attribute.dart index 74499188..9cac136c 100644 --- a/lib/src/matchers/jest_dom/has_attribute.dart +++ b/lib/src/matchers/jest_dom/has_attribute.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/matchers/jest_dom/has_description.dart b/lib/src/matchers/jest_dom/has_description.dart index c7d39f81..e8db8274 100644 --- a/lib/src/matchers/jest_dom/has_description.dart +++ b/lib/src/matchers/jest_dom/has_description.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/matchers/jest_dom/has_form_values.dart b/lib/src/matchers/jest_dom/has_form_values.dart index 44b09067..9edd5bc8 100644 --- a/lib/src/matchers/jest_dom/has_form_values.dart +++ b/lib/src/matchers/jest_dom/has_form_values.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/matchers/jest_dom/has_styles.dart b/lib/src/matchers/jest_dom/has_styles.dart index 8d9baf4e..7dea34c7 100644 --- a/lib/src/matchers/jest_dom/has_styles.dart +++ b/lib/src/matchers/jest_dom/has_styles.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/matchers/jest_dom/has_text_content.dart b/lib/src/matchers/jest_dom/has_text_content.dart index fc0f8eb4..b69d686b 100644 --- a/lib/src/matchers/jest_dom/has_text_content.dart +++ b/lib/src/matchers/jest_dom/has_text_content.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/matchers/jest_dom/has_value.dart b/lib/src/matchers/jest_dom/has_value.dart index 0170f5db..41a9bd20 100644 --- a/lib/src/matchers/jest_dom/has_value.dart +++ b/lib/src/matchers/jest_dom/has_value.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/matchers/jest_dom/is_checked.dart b/lib/src/matchers/jest_dom/is_checked.dart index 0386aa96..060ecb90 100644 --- a/lib/src/matchers/jest_dom/is_checked.dart +++ b/lib/src/matchers/jest_dom/is_checked.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/matchers/jest_dom/is_disabled.dart b/lib/src/matchers/jest_dom/is_disabled.dart index e6dd205e..b23ac32b 100644 --- a/lib/src/matchers/jest_dom/is_disabled.dart +++ b/lib/src/matchers/jest_dom/is_disabled.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/matchers/jest_dom/is_empty_dom_element.dart b/lib/src/matchers/jest_dom/is_empty_dom_element.dart index 1724e577..4c9f6c27 100644 --- a/lib/src/matchers/jest_dom/is_empty_dom_element.dart +++ b/lib/src/matchers/jest_dom/is_empty_dom_element.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/matchers/jest_dom/is_focused.dart b/lib/src/matchers/jest_dom/is_focused.dart index 3f6bff1a..dff9abc7 100644 --- a/lib/src/matchers/jest_dom/is_focused.dart +++ b/lib/src/matchers/jest_dom/is_focused.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/matchers/jest_dom/is_in_the_document.dart b/lib/src/matchers/jest_dom/is_in_the_document.dart index 320543a4..0b1ca197 100644 --- a/lib/src/matchers/jest_dom/is_in_the_document.dart +++ b/lib/src/matchers/jest_dom/is_in_the_document.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/matchers/jest_dom/is_partially_checked.dart b/lib/src/matchers/jest_dom/is_partially_checked.dart index 064c1d08..a41ec04f 100644 --- a/lib/src/matchers/jest_dom/is_partially_checked.dart +++ b/lib/src/matchers/jest_dom/is_partially_checked.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/matchers/jest_dom/util/constants.dart b/lib/src/matchers/jest_dom/util/constants.dart index efc8996c..8a112952 100644 --- a/lib/src/matchers/jest_dom/util/constants.dart +++ b/lib/src/matchers/jest_dom/util/constants.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/matchers/jest_dom/util/element_text_content_matcher_mixin.dart b/lib/src/matchers/jest_dom/util/element_text_content_matcher_mixin.dart index 4679845f..97215918 100644 --- a/lib/src/matchers/jest_dom/util/element_text_content_matcher_mixin.dart +++ b/lib/src/matchers/jest_dom/util/element_text_content_matcher_mixin.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/matchers/jest_dom/util/get_value_of.dart b/lib/src/matchers/jest_dom/util/get_value_of.dart index 8be8e83b..ca34159b 100644 --- a/lib/src/matchers/jest_dom/util/get_value_of.dart +++ b/lib/src/matchers/jest_dom/util/get_value_of.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/react/render/render.dart b/lib/src/react/render/render.dart index 1f6930ca..d4a992cb 100644 --- a/lib/src/react/render/render.dart +++ b/lib/src/react/render/render.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/react/render/types.dart b/lib/src/react/render/types.dart index b314b019..345d4e67 100644 --- a/lib/src/react/render/types.dart +++ b/lib/src/react/render/types.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/user_event/special_chars.dart b/lib/src/user_event/special_chars.dart index a3570219..ab2bcb95 100644 --- a/lib/src/user_event/special_chars.dart +++ b/lib/src/user_event/special_chars.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/user_event/user_event.dart b/lib/src/user_event/user_event.dart index dfe86499..3939680b 100644 --- a/lib/src/user_event/user_event.dart +++ b/lib/src/user_event/user_event.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/util/console_log_formatter.dart b/lib/src/util/console_log_formatter.dart index 72f91a88..56fe4105 100644 --- a/lib/src/util/console_log_formatter.dart +++ b/lib/src/util/console_log_formatter.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // This code was adapted to Dart from // https://github.com/nodejs/node-v0.x-archive/blob/master/lib/util.js diff --git a/lib/src/util/console_log_utils.dart b/lib/src/util/console_log_utils.dart index ebe6c7d3..bc97a90d 100644 --- a/lib/src/util/console_log_utils.dart +++ b/lib/src/util/console_log_utils.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/util/error_message_utils.dart b/lib/src/util/error_message_utils.dart index 04aea21e..9e0975f6 100644 --- a/lib/src/util/error_message_utils.dart +++ b/lib/src/util/error_message_utils.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/util/event_handler_error_catcher.dart b/lib/src/util/event_handler_error_catcher.dart index adba2709..c9bdeed3 100644 --- a/lib/src/util/event_handler_error_catcher.dart +++ b/lib/src/util/event_handler_error_catcher.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/util/is_or_contains.dart b/lib/src/util/is_or_contains.dart index 79eabfe2..bda1e669 100644 --- a/lib/src/util/is_or_contains.dart +++ b/lib/src/util/is_or_contains.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/src/util/js_utils.dart b/lib/src/util/js_utils.dart index fdd07a28..1615bc47 100644 --- a/lib/src/util/js_utils.dart +++ b/lib/src/util/js_utils.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/lib/user_event.dart b/lib/user_event.dart index db167fd9..8651486e 100644 --- a/lib/user_event.dart +++ b/lib/user_event.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/pubspec.yaml b/pubspec.yaml index f3946f0d..5c2d5fd9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -20,3 +20,9 @@ dev_dependencies: build_web_compilers: ">=2.12.0 <4.0.0" test_html_builder: '>=2.2.2 <4.0.0' workiva_analysis_options: ^1.0.0 + +dependency_overrides: + react: + git: + url: git@github.com:Workiva/react-dart.git + ref: null-safety-manual diff --git a/test/unit/console_log_utils_test.dart b/test/unit/console_log_utils_test.dart index a0a122e4..cb4927ff 100644 --- a/test/unit/console_log_utils_test.dart +++ b/test/unit/console_log_utils_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/dom/accessibility_helpers_test.dart b/test/unit/dom/accessibility_helpers_test.dart index 53170281..4582c3eb 100644 --- a/test/unit/dom/accessibility_helpers_test.dart +++ b/test/unit/dom/accessibility_helpers_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/dom/configure_test.dart b/test/unit/dom/configure_test.dart index 855dd5ca..fdc79b9c 100644 --- a/test/unit/dom/configure_test.dart +++ b/test/unit/dom/configure_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/dom/fire_event_test.dart b/test/unit/dom/fire_event_test.dart index 62f84b06..53387c13 100644 --- a/test/unit/dom/fire_event_test.dart +++ b/test/unit/dom/fire_event_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/dom/matchers/contains_element_test.dart b/test/unit/dom/matchers/contains_element_test.dart index 23c67c23..36d10a01 100644 --- a/test/unit/dom/matchers/contains_element_test.dart +++ b/test/unit/dom/matchers/contains_element_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/dom/matchers/css_class_matchers_test.dart b/test/unit/dom/matchers/css_class_matchers_test.dart index fe18d02d..9d343664 100644 --- a/test/unit/dom/matchers/css_class_matchers_test.dart +++ b/test/unit/dom/matchers/css_class_matchers_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/dom/matchers/has_attribute_test.dart b/test/unit/dom/matchers/has_attribute_test.dart index de4b468a..10b8d274 100644 --- a/test/unit/dom/matchers/has_attribute_test.dart +++ b/test/unit/dom/matchers/has_attribute_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/dom/matchers/has_description_test.dart b/test/unit/dom/matchers/has_description_test.dart index 440fb1db..7ef95566 100644 --- a/test/unit/dom/matchers/has_description_test.dart +++ b/test/unit/dom/matchers/has_description_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/dom/matchers/has_form_values_test.dart b/test/unit/dom/matchers/has_form_values_test.dart index 4422c4fb..2cae015f 100644 --- a/test/unit/dom/matchers/has_form_values_test.dart +++ b/test/unit/dom/matchers/has_form_values_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/dom/matchers/has_styles_test.dart b/test/unit/dom/matchers/has_styles_test.dart index 21027a5a..e8e08a2b 100644 --- a/test/unit/dom/matchers/has_styles_test.dart +++ b/test/unit/dom/matchers/has_styles_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/dom/matchers/has_text_content_test.dart b/test/unit/dom/matchers/has_text_content_test.dart index 4f4463f9..ac880180 100644 --- a/test/unit/dom/matchers/has_text_content_test.dart +++ b/test/unit/dom/matchers/has_text_content_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/dom/matchers/has_value_test.dart b/test/unit/dom/matchers/has_value_test.dart index 91c5deb1..f1599d0f 100644 --- a/test/unit/dom/matchers/has_value_test.dart +++ b/test/unit/dom/matchers/has_value_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/dom/matchers/is_checked_test.dart b/test/unit/dom/matchers/is_checked_test.dart index ede2d0b6..6ed49c1c 100644 --- a/test/unit/dom/matchers/is_checked_test.dart +++ b/test/unit/dom/matchers/is_checked_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/dom/matchers/is_disabled_test.dart b/test/unit/dom/matchers/is_disabled_test.dart index 91746aa3..b8525a33 100644 --- a/test/unit/dom/matchers/is_disabled_test.dart +++ b/test/unit/dom/matchers/is_disabled_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/dom/matchers/is_empty_dom_element_test.dart b/test/unit/dom/matchers/is_empty_dom_element_test.dart index f93e63ec..eb3c2f9e 100644 --- a/test/unit/dom/matchers/is_empty_dom_element_test.dart +++ b/test/unit/dom/matchers/is_empty_dom_element_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/dom/matchers/is_focused_test.dart b/test/unit/dom/matchers/is_focused_test.dart index bb7e0cc8..0cccb39f 100644 --- a/test/unit/dom/matchers/is_focused_test.dart +++ b/test/unit/dom/matchers/is_focused_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/dom/matchers/is_in_the_document_test.dart b/test/unit/dom/matchers/is_in_the_document_test.dart index ec308745..cda007c3 100644 --- a/test/unit/dom/matchers/is_in_the_document_test.dart +++ b/test/unit/dom/matchers/is_in_the_document_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/dom/matchers/is_partially_checked_test.dart b/test/unit/dom/matchers/is_partially_checked_test.dart index 3e27317d..8afb7aeb 100644 --- a/test/unit/dom/matchers/is_partially_checked_test.dart +++ b/test/unit/dom/matchers/is_partially_checked_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/dom/pretty_dom_test.dart b/test/unit/dom/pretty_dom_test.dart index 214d3977..1f85cb57 100644 --- a/test/unit/dom/pretty_dom_test.dart +++ b/test/unit/dom/pretty_dom_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/dom/queries/by_label_text_test.dart b/test/unit/dom/queries/by_label_text_test.dart index c0638980..7778a51e 100644 --- a/test/unit/dom/queries/by_label_text_test.dart +++ b/test/unit/dom/queries/by_label_text_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/dom/queries/by_role_test.dart b/test/unit/dom/queries/by_role_test.dart index ead57ea4..b43fb9d0 100644 --- a/test/unit/dom/queries/by_role_test.dart +++ b/test/unit/dom/queries/by_role_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/dom/queries/by_testid_test.dart b/test/unit/dom/queries/by_testid_test.dart index 22e84fbf..6e39bb49 100644 --- a/test/unit/dom/queries/by_testid_test.dart +++ b/test/unit/dom/queries/by_testid_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/dom/queries/by_text_test.dart b/test/unit/dom/queries/by_text_test.dart index adda56e0..30369089 100644 --- a/test/unit/dom/queries/by_text_test.dart +++ b/test/unit/dom/queries/by_text_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/dom/queries/shared/scoped_queries_tests.dart b/test/unit/dom/queries/shared/scoped_queries_tests.dart index 906eac49..f4b5fe5a 100644 --- a/test/unit/dom/queries/shared/scoped_queries_tests.dart +++ b/test/unit/dom/queries/shared/scoped_queries_tests.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/dom/queries/shared/text_match_type_parsing_tests.dart b/test/unit/dom/queries/shared/text_match_type_parsing_tests.dart index 65d65a02..1792a2d3 100644 --- a/test/unit/dom/queries/shared/text_match_type_parsing_tests.dart +++ b/test/unit/dom/queries/shared/text_match_type_parsing_tests.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/dom/text_match_test.dart b/test/unit/dom/text_match_test.dart index b1edf6f8..0cd0311e 100644 --- a/test/unit/dom/text_match_test.dart +++ b/test/unit/dom/text_match_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // ignore_for_file: prefer_interpolation_to_compose_strings // Copyright 2021 Workiva Inc. diff --git a/test/unit/dom/top_level_queries_test.dart b/test/unit/dom/top_level_queries_test.dart index d10c65fd..6184fdde 100644 --- a/test/unit/dom/top_level_queries_test.dart +++ b/test/unit/dom/top_level_queries_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/dom/wait_for_test.dart b/test/unit/dom/wait_for_test.dart index dd641ed0..b13cad6c 100644 --- a/test/unit/dom/wait_for_test.dart +++ b/test/unit/dom/wait_for_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/dom/within_test.dart b/test/unit/dom/within_test.dart index 32ecb639..eeb8d723 100644 --- a/test/unit/dom/within_test.dart +++ b/test/unit/dom/within_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/react/render_test.dart b/test/unit/react/render_test.dart index c0024c0b..daf513d7 100644 --- a/test/unit/react/render_test.dart +++ b/test/unit/react/render_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/user_event/clear_test.dart b/test/unit/user_event/clear_test.dart index 6af43070..6e2e17c7 100644 --- a/test/unit/user_event/clear_test.dart +++ b/test/unit/user_event/clear_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/user_event/click_test.dart b/test/unit/user_event/click_test.dart index 1ec1ec9f..e8db1340 100644 --- a/test/unit/user_event/click_test.dart +++ b/test/unit/user_event/click_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/user_event/hover_test.dart b/test/unit/user_event/hover_test.dart index b7816ebc..c9ca7644 100644 --- a/test/unit/user_event/hover_test.dart +++ b/test/unit/user_event/hover_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/user_event/paste_test.dart b/test/unit/user_event/paste_test.dart index ec8ecc31..a268d41c 100644 --- a/test/unit/user_event/paste_test.dart +++ b/test/unit/user_event/paste_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/user_event/select_options_test.dart b/test/unit/user_event/select_options_test.dart index 2131adea..2b31cc57 100644 --- a/test/unit/user_event/select_options_test.dart +++ b/test/unit/user_event/select_options_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/user_event/special_chars_test.dart b/test/unit/user_event/special_chars_test.dart index 11b8918f..b64c4971 100644 --- a/test/unit/user_event/special_chars_test.dart +++ b/test/unit/user_event/special_chars_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/user_event/tab_test.dart b/test/unit/user_event/tab_test.dart index 2cc69686..44f944ce 100644 --- a/test/unit/user_event/tab_test.dart +++ b/test/unit/user_event/tab_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/user_event/type_test.dart b/test/unit/user_event/type_test.dart index cfbf8f68..555f5bb7 100644 --- a/test/unit/user_event/type_test.dart +++ b/test/unit/user_event/type_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/user_event/upload_test.dart b/test/unit/user_event/upload_test.dart index 34f41bb8..a7a6582c 100644 --- a/test/unit/user_event/upload_test.dart +++ b/test/unit/user_event/upload_test.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/util/constants.dart b/test/unit/util/constants.dart index 462f65b6..ce0e50bd 100644 --- a/test/unit/util/constants.dart +++ b/test/unit/util/constants.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/util/enums.dart b/test/unit/util/enums.dart index 3d6f0acb..e81867f1 100644 --- a/test/unit/util/enums.dart +++ b/test/unit/util/enums.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/util/event_handler_error.dart b/test/unit/util/event_handler_error.dart index d41a8176..292027f4 100644 --- a/test/unit/util/event_handler_error.dart +++ b/test/unit/util/event_handler_error.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/util/exception.dart b/test/unit/util/exception.dart index ac7781c2..a75d9c8c 100644 --- a/test/unit/util/exception.dart +++ b/test/unit/util/exception.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/util/init.dart b/test/unit/util/init.dart index 5b3718b7..2e65f958 100644 --- a/test/unit/util/init.dart +++ b/test/unit/util/init.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/util/matchers.dart b/test/unit/util/matchers.dart index 219d5de4..c451087a 100644 --- a/test/unit/util/matchers.dart +++ b/test/unit/util/matchers.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/util/over_react_stubs.dart b/test/unit/util/over_react_stubs.dart index cc50cdf7..7f0896f7 100644 --- a/test/unit/util/over_react_stubs.dart +++ b/test/unit/util/over_react_stubs.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/util/prints_and_logs_recording.dart b/test/unit/util/prints_and_logs_recording.dart index 9c07cc6b..702591fb 100644 --- a/test/unit/util/prints_and_logs_recording.dart +++ b/test/unit/util/prints_and_logs_recording.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/util/rendering.dart b/test/unit/util/rendering.dart index bb4959f3..1ad209ad 100644 --- a/test/unit/util/rendering.dart +++ b/test/unit/util/rendering.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/util/shadow_dom.dart b/test/unit/util/shadow_dom.dart index 8c1bfb24..53edfa98 100644 --- a/test/unit/util/shadow_dom.dart +++ b/test/unit/util/shadow_dom.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // diff --git a/test/unit/util/string_trimming.dart b/test/unit/util/string_trimming.dart index 7dbbc5d5..c117c80b 100644 --- a/test/unit/util/string_trimming.dart +++ b/test/unit/util/string_trimming.dart @@ -1,4 +1,3 @@ -// @dart = 2.7 // Copyright 2021 Workiva Inc. // From be7cb23e912b7ef935f6810322d184f40908a3a4 Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Thu, 15 Jun 2023 16:35:00 -0500 Subject: [PATCH 02/31] Add hints part 1 --- lib/src/dom/accessibility_helpers.dart | 4 ++-- lib/src/dom/async/wait_for.dart | 4 ++-- lib/src/matchers/jest_dom/is_checked.dart | 4 ++-- lib/src/matchers/jest_dom/is_disabled.dart | 2 +- .../matchers/jest_dom/is_partially_checked.dart | 2 +- lib/src/react/render/render.dart | 4 ++-- lib/src/user_event/user_event.dart | 15 +++++++++------ lib/src/util/is_or_contains.dart | 2 +- lib/src/util/js_utils.dart | 4 ++-- test/unit/dom/accessibility_helpers_test.dart | 2 +- test/unit/dom/fire_event_test.dart | 2 +- test/unit/dom/matchers/has_description_test.dart | 4 ---- test/unit/dom/matchers/has_form_values_test.dart | 3 --- test/unit/dom/matchers/has_styles_test.dart | 2 -- test/unit/dom/matchers/has_text_content_test.dart | 4 ---- test/unit/dom/matchers/has_value_test.dart | 5 +---- test/unit/dom/queries/by_label_text_test.dart | 3 --- test/unit/dom/queries/by_role_test.dart | 15 ++++++--------- test/unit/dom/queries/by_testid_test.dart | 3 --- test/unit/dom/queries/by_text_test.dart | 3 --- .../dom/queries/shared/scoped_queries_tests.dart | 14 +++++--------- .../shared/text_match_type_parsing_tests.dart | 15 ++++----------- test/unit/dom/top_level_queries_test.dart | 13 +++---------- test/unit/dom/wait_for_test.dart | 2 +- test/unit/dom/within_test.dart | 4 +--- test/unit/react/render_test.dart | 4 +--- test/unit/user_event/click_test.dart | 2 +- test/unit/user_event/hover_test.dart | 4 ++-- test/unit/user_event/paste_test.dart | 6 +++--- test/unit/user_event/select_options_test.dart | 4 ++-- test/unit/user_event/tab_test.dart | 2 +- test/unit/user_event/type_test.dart | 4 ++-- test/unit/user_event/upload_test.dart | 4 ++-- test/unit/util/init.dart | 2 +- test/unit/util/over_react_stubs.dart | 7 +++++++ test/unit/util/rendering.dart | 4 ++-- 36 files changed, 69 insertions(+), 109 deletions(-) diff --git a/lib/src/dom/accessibility_helpers.dart b/lib/src/dom/accessibility_helpers.dart index 7fc31347..1615ba4e 100644 --- a/lib/src/dom/accessibility_helpers.dart +++ b/lib/src/dom/accessibility_helpers.dart @@ -34,7 +34,7 @@ import 'package:react_testing_library/src/util/console_log_utils.dart'; /// /// {@category Accessibility} Map getRoles(Node container, {bool hidden = false}) => - Map.from(JsBackedMap.fromJs(_getRoles(container, jsifyAndAllowInterop({'hidden': hidden}) as JsMap))); + Map.from(JsBackedMap.fromJs(_getRoles(container, jsifyAndAllowInterop({'hidden': hidden}) as JsMap/*!*/))); /// Prints a list of all the implicit ARIA roles within [container], each role containing a list of all of the /// nodes which match that role. @@ -47,7 +47,7 @@ Map getRoles(Node container, {bool hidden = false}) => /// /// {@category Accessibility} void logRoles(Node container, {bool hidden = false}) => - printConsoleLogs(() => _logRoles(container, jsifyAndAllowInterop({'hidden': hidden}) as JsMap)); + printConsoleLogs(() => _logRoles(container, jsifyAndAllowInterop({'hidden': hidden}) as JsMap/*!*/)); @JS('rtl.getRoles') external JsMap _getRoles( diff --git a/lib/src/dom/async/wait_for.dart b/lib/src/dom/async/wait_for.dart index 199f0ed2..e11f2153 100644 --- a/lib/src/dom/async/wait_for.dart +++ b/lib/src/dom/async/wait_for.dart @@ -157,7 +157,7 @@ Future waitFor( /// /// {@category Async} Future waitForElementToBeRemoved( - Node Function() callback, { + Node/*!*/ Function() callback, { Node container, Duration timeout, Duration interval = const Duration(milliseconds: 50), @@ -214,7 +214,7 @@ Future waitForElementToBeRemoved( /// /// {@category Async} Future waitForElementsToBeRemoved( - List Function() callback, { + List/*!*/ Function() callback, { Node container, Duration timeout, Duration interval = const Duration(milliseconds: 50), diff --git a/lib/src/matchers/jest_dom/is_checked.dart b/lib/src/matchers/jest_dom/is_checked.dart index 060ecb90..6dea5637 100644 --- a/lib/src/matchers/jest_dom/is_checked.dart +++ b/lib/src/matchers/jest_dom/is_checked.dart @@ -94,7 +94,7 @@ class _IsChecked extends Matcher { bool isElementThatCanBeChecked(dynamic item, Map matchState) => item != null && matchState['isElement'] as bool && matchState['canBeChecked'] as bool; - bool isElementChecked(Element item, Map matchState) { + bool/*!*/ isElementChecked(Element item, Map matchState) { if (item is InputElement) { final type = item.getAttribute('type'); if (_validTypes.contains(type)) { @@ -125,7 +125,7 @@ class _IsChecked extends Matcher { if (!isElementThatCanBeChecked(item, matchState)) return false; - return isElementChecked(item as Element, matchState); + return isElementChecked(item as Element/*!*/, matchState); } @override diff --git a/lib/src/matchers/jest_dom/is_disabled.dart b/lib/src/matchers/jest_dom/is_disabled.dart index b23ac32b..cadafd5b 100644 --- a/lib/src/matchers/jest_dom/is_disabled.dart +++ b/lib/src/matchers/jest_dom/is_disabled.dart @@ -85,7 +85,7 @@ class _IsDisabled extends Matcher { bool isElementThatCanBeDisabled(dynamic item, Map matchState) => item != null && matchState['isElement'] as bool && matchState['canBeDisabled'] as bool; - bool isElementDisabled(dynamic item, Map matchState) { + bool/*!*/ isElementDisabled(dynamic item, Map matchState) { if (!isElementThatCanBeDisabled(item, matchState)) return false; final formAncestor = (item as Element).closest('form'); if (formAncestor != null && (formAncestor as FormElement).hasAttribute('disabled')) return true; diff --git a/lib/src/matchers/jest_dom/is_partially_checked.dart b/lib/src/matchers/jest_dom/is_partially_checked.dart index a41ec04f..dc41426e 100644 --- a/lib/src/matchers/jest_dom/is_partially_checked.dart +++ b/lib/src/matchers/jest_dom/is_partially_checked.dart @@ -98,7 +98,7 @@ class _IsPartiallyChecked extends Matcher { bool isElementThatCanBePartiallyChecked(dynamic item, Map matchState) => item != null && matchState['isElement'] as bool && matchState['canBePartiallyChecked'] as bool; - bool isElementPartiallyChecked(dynamic item, Map matchState) { + bool/*!*/ isElementPartiallyChecked(dynamic item, Map matchState) { if (item is! Element) return false; if (item is InputElement) { diff --git a/lib/src/react/render/render.dart b/lib/src/react/render/render.dart index d4a992cb..6049ca62 100644 --- a/lib/src/react/render/render.dart +++ b/lib/src/react/render/render.dart @@ -106,7 +106,7 @@ import 'package:react_testing_library/src/react/render/types.dart' show JsRender /// At this time, the Dart API does not support them. If you have a use case for custom queries - /// [we would love to hear more about it!](https://github.com/Workiva/react_testing_library/issues/new) RenderResult render( - ReactElement ui, { + ReactElement/*!*/ ui, { Node container, Node baseElement, bool hydrate = false, @@ -202,7 +202,7 @@ class RenderResult extends ScopedQueries { /// Updates the props of the [renderedElement] by providing an updated [ui] element. /// /// > See: - void rerender(ReactElement ui) { + void rerender(ReactElement/*!*/ ui) { _renderedElement = ui; _jsRenderResult.rerender(ui); } diff --git a/lib/src/user_event/user_event.dart b/lib/src/user_event/user_event.dart index 3939680b..5d86e9f0 100644 --- a/lib/src/user_event/user_event.dart +++ b/lib/src/user_event/user_event.dart @@ -304,7 +304,7 @@ abstract class UserEvent { /// /// {@category UserActions} static void type( - Element element, + Element/*!*/ element, String text, { bool skipClick = false, bool skipAutoClose = false, @@ -420,7 +420,7 @@ abstract class UserEvent { /// /// {@category UserActions} static Future typeWithDelay( - Element element, + Element/*!*/ element, String text, Duration delay, { bool skipClick = false, @@ -534,7 +534,7 @@ abstract class UserEvent { return getProperty(_userEvent, 'keyboard')( text, jsifyAndAllowInterop(options), - ) as KeyboardState; + ) as KeyboardState/*!*/; }); } @@ -1389,7 +1389,7 @@ abstract class UserEvent { /// /// {@category UserActions} static void paste( - Element element, + Element/*!*/ element, String text, { Map eventInit, int initialSelectionStart, @@ -1427,10 +1427,13 @@ dynamic _jsifyEventData(Map eventData) => jsifyAndAllowInterop(eventData ?? cons List _unjsifyFileList(List fileList) { if (fileList is FileList) return fileList; - final jsFileList = JsBackedMap.fromJs(fileList as JsMap); + final jsFileList = JsBackedMap.fromJs((fileList ?? []) as JsMap); final convertedFiles = []; for (var i = 0; i < (jsFileList['length'] as int); i++) { - convertedFiles.add(jsFileList['item'](i) as File); + final file = jsFileList['item'](i); + if(file is File) { + convertedFiles.add(file); + } } return convertedFiles; } diff --git a/lib/src/util/is_or_contains.dart b/lib/src/util/is_or_contains.dart index bda1e669..3ea8f398 100644 --- a/lib/src/util/is_or_contains.dart +++ b/lib/src/util/is_or_contains.dart @@ -18,4 +18,4 @@ import 'dart:html' show Node; /// Returns whether [root] is the same as or contains the [other] node. /// /// Returns false if either [root] or [other] is null. -bool isOrContains(Node root, Node other) => (root != null && other != null) && (root == other || root.contains(other)); +bool isOrContains(Node/*!*/ root, Node other) => (root != null && other != null) && (root == other || root.contains(other)); diff --git a/lib/src/util/js_utils.dart b/lib/src/util/js_utils.dart index 1615bc47..01349683 100644 --- a/lib/src/util/js_utils.dart +++ b/lib/src/util/js_utils.dart @@ -17,11 +17,11 @@ import 'dart:js'; /// [Global JavaScript Array Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) // ignore: type_annotate_public_apis -final jsArray = context['Array'] as JsObject; +final jsArray = context['Array'] as JsObject/*!*/; /// Store a helper reference to the global [jsArray]'s [`slice` method](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice) // ignore: type_annotate_public_apis -final arrayProtoSlice = jsArray['prototype']['slice'] as JsObject; +final arrayProtoSlice = jsArray['prototype']['slice'] as JsObject/*!*/; /// Converts the Array-like [object] to a [JsArray] using [arrayProtoSlice]. JsArray convertToArray(JsObject object) { diff --git a/test/unit/dom/accessibility_helpers_test.dart b/test/unit/dom/accessibility_helpers_test.dart index 4582c3eb..99810b38 100644 --- a/test/unit/dom/accessibility_helpers_test.dart +++ b/test/unit/dom/accessibility_helpers_test.dart @@ -187,7 +187,7 @@ void main() { }); group('getRoles', () { - Map _getLoggedRoleMatches(Node dom, {bool hidden = false}) { + Map _getLoggedRoleMatches(Node dom, {bool hidden = false}) { final rolePattern = RegExp(r'(\w*):\n\n((.|(\n(?!-)))*)\n\n---'); final printCalls = recordPrintCalls(() => rtl.logRoles(dom, hidden: hidden)); expect(printCalls, hasLength(1)); diff --git a/test/unit/dom/fire_event_test.dart b/test/unit/dom/fire_event_test.dart index 53387c13..68d4508f 100644 --- a/test/unit/dom/fire_event_test.dart +++ b/test/unit/dom/fire_event_test.dart @@ -33,7 +33,7 @@ void main() { final elementToRender = react.button({ 'id': 'root', 'onClick': (event) { - calls.add((event as react.SyntheticMouseEvent).nativeEvent as Event); + calls.add((event as react.SyntheticMouseEvent).nativeEvent as Event/*!*/); } }, 'oh hai') as ReactElement; view = rtl.render(elementToRender); diff --git a/test/unit/dom/matchers/has_description_test.dart b/test/unit/dom/matchers/has_description_test.dart index 7ef95566..de3b67b9 100644 --- a/test/unit/dom/matchers/has_description_test.dart +++ b/test/unit/dom/matchers/has_description_test.dart @@ -46,10 +46,6 @@ void main() { ) as ReactElement); }); - tearDown(() { - view = null; - }); - group('[element with a single id as its aria-describedby attribute value]', () { Element closeButtonElement; setUp(() { diff --git a/test/unit/dom/matchers/has_form_values_test.dart b/test/unit/dom/matchers/has_form_values_test.dart index 2cae015f..85a10c26 100644 --- a/test/unit/dom/matchers/has_form_values_test.dart +++ b/test/unit/dom/matchers/has_form_values_test.dart @@ -57,9 +57,6 @@ void main() { } RenderResult view; - tearDown(() { - view = null; - }); group('passes when provided with a valid name/value combination for a', () { final unTestedChildFormElemThatShouldNotCauseFailure = _FormElemDefinition(react.input, { diff --git a/test/unit/dom/matchers/has_styles_test.dart b/test/unit/dom/matchers/has_styles_test.dart index e8e08a2b..f6c4635f 100644 --- a/test/unit/dom/matchers/has_styles_test.dart +++ b/test/unit/dom/matchers/has_styles_test.dart @@ -30,9 +30,7 @@ void main() { StyleElement externalStyleSheet; tearDown(() { - view = null; externalStyleSheet?.remove(); - externalStyleSheet = null; }); setUp(() { diff --git a/test/unit/dom/matchers/has_text_content_test.dart b/test/unit/dom/matchers/has_text_content_test.dart index ac880180..fbf5cdbf 100644 --- a/test/unit/dom/matchers/has_text_content_test.dart +++ b/test/unit/dom/matchers/has_text_content_test.dart @@ -35,10 +35,6 @@ void main() { rootElement = view.getByTestId('root'); }); - tearDown(() { - rootElement = null; - }); - group('passes when provided a', () { group('String that is an exact match of the element text content', () { test('when normalizeWhitespace = true (default)', () { diff --git a/test/unit/dom/matchers/has_value_test.dart b/test/unit/dom/matchers/has_value_test.dart index f1599d0f..bce1eee5 100644 --- a/test/unit/dom/matchers/has_value_test.dart +++ b/test/unit/dom/matchers/has_value_test.dart @@ -30,12 +30,9 @@ void main() { @isTestGroup void sharedHasValueTests(String description, - {Matcher Function([dynamic]) matcherFn, String valueDescription = 'value'}) { + {@required Matcher Function([dynamic]) matcherFn, String valueDescription = 'value'}) { group(description, () { RenderResult view; - tearDown(() { - view = null; - }); group('passes when the provided value matches the value found in a', () { group('TextInputElement', () { diff --git a/test/unit/dom/queries/by_label_text_test.dart b/test/unit/dom/queries/by_label_text_test.dart index 7778a51e..e59cd2c9 100644 --- a/test/unit/dom/queries/by_label_text_test.dart +++ b/test/unit/dom/queries/by_label_text_test.dart @@ -30,9 +30,6 @@ void main() { initConfigForInternalTesting(); rtl.RenderResult view; - tearDown(() { - view = null; - }); group( 'the selector argument can be specified to target only matching ' diff --git a/test/unit/dom/queries/by_role_test.dart b/test/unit/dom/queries/by_role_test.dart index b43fb9d0..ece55d81 100644 --- a/test/unit/dom/queries/by_role_test.dart +++ b/test/unit/dom/queries/by_role_test.dart @@ -30,10 +30,7 @@ void main() { initConfigForInternalTesting(); rtl.RenderResult view; - Ref emptyElementRef; - tearDown(() { - view = null; - }); + Ref/*!*/ emptyElementRef; group('when more than one element has the same role,', () { setUp(() { @@ -768,14 +765,14 @@ ReactElement renderButton({bool pressed = false, bool expanded = false}) { 'aria-expanded': expanded, }, 'Click me', - ) as ReactElement; + ) as ReactElement/*!*/; } ReactElement renderDialog() { return react.div( {'role': 'dialog'}, 'Read me', - ) as ReactElement; + ) as ReactElement/*!*/; } ReactElement renderTab({bool selected = false}) { @@ -786,7 +783,7 @@ ReactElement renderTab({bool selected = false}) { 'aria-selected': selected, }, 'Select me', - ) as ReactElement; + ) as ReactElement/*!*/; } ReactElement renderCheckbox({bool checked = false}) { @@ -797,7 +794,7 @@ ReactElement renderCheckbox({bool checked = false}) { 'aria-checked': checked, }, 'Check me out', - ) as ReactElement; + ) as ReactElement/*!*/; } ReactElement renderCheckboxWithSwitchAsFallback({bool checked = false}) { @@ -808,5 +805,5 @@ ReactElement renderCheckboxWithSwitchAsFallback({bool checked = false}) { 'aria-checked': checked, }, 'Check me out', - ) as ReactElement; + ) as ReactElement/*!*/; } diff --git a/test/unit/dom/queries/by_testid_test.dart b/test/unit/dom/queries/by_testid_test.dart index 6e39bb49..01b16f32 100644 --- a/test/unit/dom/queries/by_testid_test.dart +++ b/test/unit/dom/queries/by_testid_test.dart @@ -31,9 +31,6 @@ void main() { initConfigForInternalTesting(); rtl.RenderResult view; - tearDown(() { - view = null; - }); group('basic functionality', () { setUp(() { diff --git a/test/unit/dom/queries/by_text_test.dart b/test/unit/dom/queries/by_text_test.dart index 30369089..7c1cd2fb 100644 --- a/test/unit/dom/queries/by_text_test.dart +++ b/test/unit/dom/queries/by_text_test.dart @@ -30,9 +30,6 @@ void main() { initConfigForInternalTesting(); rtl.RenderResult view; - tearDown(() { - view = null; - }); group( 'the selector argument can be specified to target only matching ' diff --git a/test/unit/dom/queries/shared/scoped_queries_tests.dart b/test/unit/dom/queries/shared/scoped_queries_tests.dart index f4b5fe5a..5fc1a2c9 100644 --- a/test/unit/dom/queries/shared/scoped_queries_tests.dart +++ b/test/unit/dom/queries/shared/scoped_queries_tests.dart @@ -45,12 +45,9 @@ void hasQueriesScopedTo( getWrapper, {bool isGloballyScoped = true}) { group('$scopeName:', () { - ScopedQueries queries; - String expectedPrettyDom; + String/*!*/ expectedPrettyDom; - initConfigForInternalTesting(() { - queries = null; - }); + initConfigForInternalTesting(); ScopedQueries renderAndGetQueries({ bool testAsyncQuery = false, @@ -94,18 +91,17 @@ void hasQueriesScopedTo( final wrapper = getWrapper(scopeName, testAsyncQuery: testAsyncQuery, renderMultipleElsMatchingQuery: renderMultipleElsMatchingQuery); - queries ??= wrapper.queries; renderResult = wrapper.renderResult; if (!testAsyncQuery) { expectedPrettyDom = prettyDOM(getQueryContainer(renderResult)); } - return queries; + return wrapper.queries; } test('exposes all the expected queries', () { - queries = renderAndGetQueries(); + final queries = renderAndGetQueries(); expect(queries.getByAltText, isA(), reason: 'getByAltText'); expect(queries.getAllByAltText, isA(), reason: 'getAllByAltText'); @@ -422,7 +418,7 @@ void hasQueriesScopedTo( document.body.append(outOfScopeElement); addTearDown(outOfScopeElement.remove); - queries = renderAndGetQueries(); + final queries = renderAndGetQueries(); if (queries.getContainerForScope() != document.body) { expect(queries.queryByText('out-of-scope'), isNull, reason: 'The scoped query should not return elements that are not found within the scoped container.'); diff --git a/test/unit/dom/queries/shared/text_match_type_parsing_tests.dart b/test/unit/dom/queries/shared/text_match_type_parsing_tests.dart index 1792a2d3..8cc8a667 100644 --- a/test/unit/dom/queries/shared/text_match_type_parsing_tests.dart +++ b/test/unit/dom/queries/shared/text_match_type_parsing_tests.dart @@ -91,7 +91,7 @@ void testTextMatchTypes( assert(getContainerForTopLevelQueries != null); } - Matcher toThrowErrorMatchingInlineSnapshotPattern(String valueExpectedButNotFound) { + Matcher toThrowErrorMatchingInlineSnapshotPattern(String/*!*/ valueExpectedButNotFound) { Matcher containsMatcher; if (failureSnapshotPattern != null) { containsMatcher = buildContainsPatternUsing(failureSnapshotPattern, valueExpectedButNotFound); @@ -140,7 +140,7 @@ void testTextMatchTypes( } test('$queryName query', () async { - String queryFnString; + String/*!*/ queryFnString; final queryFn = queryGetter(); final container = getContainerForTopLevelQueries?.call(); dynamic Function() getQueryResult; @@ -203,9 +203,9 @@ void testTextMatchTypes( NormalizerFn Function([NormalizerOptions]) normalizer, bool containerArgRequired = false, }) { - String queryFnString; + String/*!*/ queryFnString; Function queryFn; - Node container; + Node/*!*/ container; dynamic Function() getQueryResult; void sharedSetup({bool renderMultipleElsMatchingQuery = false}) { @@ -251,13 +251,6 @@ void testTextMatchTypes( } } - tearDown(() { - queryFnString = null; - queryFn = null; - container = null; - getQueryResult = null; - }); - test('$queryName query [single element matched]', () async { sharedSetup(renderMultipleElsMatchingQuery: false); diff --git a/test/unit/dom/top_level_queries_test.dart b/test/unit/dom/top_level_queries_test.dart index 6184fdde..a07321d0 100644 --- a/test/unit/dom/top_level_queries_test.dart +++ b/test/unit/dom/top_level_queries_test.dart @@ -15,7 +15,6 @@ import 'dart:html'; -import 'package:react/react_client.dart' show ReactElement; import 'package:react_testing_library/react_testing_library.dart' as rtl; import 'package:test/test.dart'; @@ -83,12 +82,8 @@ void main() { group('contains queries that can be scoped to the specified container', () { const scopeName = 'top level'; - Node container; - String expectedPrettyDom; - - tearDown(() { - container = null; - }); + Node/*!*/ container; + String/*!*/ expectedPrettyDom; Function _renderForQuery( Function query, { @@ -98,9 +93,7 @@ void main() { final elsForQuerying = elementsForQuerying(scopeName, renderMultipleElsMatchingQuery: renderMultipleElsMatchingQuery); final els = testAsyncQuery - // TODO: Remove ignore once we stop supporting Dart SDK 2.7.x - // ignore: unnecessary_cast - ? DelayedRenderOf({'childrenToRenderAfterDelay': elsForQuerying}) as ReactElement + ? DelayedRenderOf({'childrenToRenderAfterDelay': elsForQuerying}) : elsForQuerying; final view = rtl.render(els); container = view.container; diff --git a/test/unit/dom/wait_for_test.dart b/test/unit/dom/wait_for_test.dart index b13cad6c..5a40d32a 100644 --- a/test/unit/dom/wait_for_test.dart +++ b/test/unit/dom/wait_for_test.dart @@ -33,7 +33,7 @@ void main() { initConfigForInternalTesting(); rtl.RenderResult view; - Element rootElement; + Element/*!*/ rootElement; group('waitFor()', () { setUp(() { diff --git a/test/unit/dom/within_test.dart b/test/unit/dom/within_test.dart index eeb8d723..34f37c02 100644 --- a/test/unit/dom/within_test.dart +++ b/test/unit/dom/within_test.dart @@ -37,9 +37,7 @@ void main() { final elsForQuerying = elementsForQuerying(scopeName, renderMultipleElsMatchingQuery: renderMultipleElsMatchingQuery); final els = testAsyncQuery - // TODO: Remove ignore once we stop supporting Dart SDK 2.7.x - // ignore: unnecessary_cast - ? DelayedRenderOf({'childrenToRenderAfterDelay': elsForQuerying}) as ReactElement + ? DelayedRenderOf({'childrenToRenderAfterDelay': elsForQuerying}) : elsForQuerying; final view = rtl.render(els); final queries = rtl.within(view.container); diff --git a/test/unit/react/render_test.dart b/test/unit/react/render_test.dart index daf513d7..989ffba6 100644 --- a/test/unit/react/render_test.dart +++ b/test/unit/react/render_test.dart @@ -55,9 +55,7 @@ void main() { final elsForQuerying = elementsForQuerying(scopeName, renderMultipleElsMatchingQuery: renderMultipleElsMatchingQuery); final els = testAsyncQuery - // TODO: Remove ignore once we stop supporting Dart SDK 2.7.x - // ignore: unnecessary_cast - ? DelayedRenderOf({'childrenToRenderAfterDelay': elsForQuerying}) as ReactElement + ? DelayedRenderOf({'childrenToRenderAfterDelay': elsForQuerying}) : elsForQuerying; return ScopedQueriesTestWrapper(rtl.render(els)); }); diff --git a/test/unit/user_event/click_test.dart b/test/unit/user_event/click_test.dart index e8db1340..4f42eb6b 100644 --- a/test/unit/user_event/click_test.dart +++ b/test/unit/user_event/click_test.dart @@ -36,7 +36,7 @@ void main() { final elementToRender = react.button({ 'id': 'root', 'onClick': (event) { - calls.add((event as react.SyntheticMouseEvent).nativeEvent as MouseEvent); + calls.add((event as react.SyntheticMouseEvent).nativeEvent as MouseEvent/*!*/); }, // Count mouseover events to find out how many hover events occur. 'onMouseOver': (_) => hoverEventCount++, diff --git a/test/unit/user_event/hover_test.dart b/test/unit/user_event/hover_test.dart index c9ca7644..3340e687 100644 --- a/test/unit/user_event/hover_test.dart +++ b/test/unit/user_event/hover_test.dart @@ -102,11 +102,11 @@ ReactDartFunctionComponentFactoryProxy HoverTestComponent = react.registerFuncti react.button({ 'onMouseOver': (e) { isShown.set(true); - props['calls'].add((e as react.SyntheticMouseEvent).nativeEvent as MouseEvent); + props['calls'].add((e as react.SyntheticMouseEvent).nativeEvent as MouseEvent/*!*/); }, 'onMouseOut': (e) { isShown.set(false); - props['calls'].add((e as react.SyntheticMouseEvent).nativeEvent as MouseEvent); + props['calls'].add((e as react.SyntheticMouseEvent).nativeEvent as MouseEvent/*!*/); } }, [ 'Hover over me!' diff --git a/test/unit/user_event/paste_test.dart b/test/unit/user_event/paste_test.dart index a268d41c..470cc18e 100644 --- a/test/unit/user_event/paste_test.dart +++ b/test/unit/user_event/paste_test.dart @@ -28,7 +28,7 @@ void main() { group('UserEvent.paste', () { List calls; rtl.RenderResult view; - InputElement input; + InputElement/*!*/ input; setUp(() { calls = []; @@ -44,7 +44,7 @@ void main() { setUp(() { final elementToRender = react.input({ 'onPaste': (event) { - calls.add((event as react.SyntheticClipboardEvent).nativeEvent as ClipboardEvent); + calls.add((event as react.SyntheticClipboardEvent).nativeEvent as ClipboardEvent/*!*/); }, }); @@ -70,7 +70,7 @@ void main() { setUp(() { final elementToRender = react.input({ 'onPaste': (event) { - calls.add((event as react.SyntheticClipboardEvent).nativeEvent as ClipboardEvent); + calls.add((event as react.SyntheticClipboardEvent).nativeEvent as ClipboardEvent/*!*/); }, 'defaultValue': 'this is a bad example', }); diff --git a/test/unit/user_event/select_options_test.dart b/test/unit/user_event/select_options_test.dart index 2b31cc57..81762a90 100644 --- a/test/unit/user_event/select_options_test.dart +++ b/test/unit/user_event/select_options_test.dart @@ -37,7 +37,7 @@ void main() { view = rtl.render(react.select({ 'id': 'root', 'onClick': (event) { - calls.add((event as react.SyntheticMouseEvent).nativeEvent as MouseEvent); + calls.add((event as react.SyntheticMouseEvent).nativeEvent as MouseEvent/*!*/); }, 'multiple': isMultiSelect, }, [ @@ -144,7 +144,7 @@ void main() { view = rtl.render(react.select({ 'id': 'root', 'onClick': (event) { - calls.add((event as react.SyntheticMouseEvent).nativeEvent as MouseEvent); + calls.add((event as react.SyntheticMouseEvent).nativeEvent as MouseEvent/*!*/); }, 'multiple': true, 'defaultValue': ['1', '2', '3'], diff --git a/test/unit/user_event/tab_test.dart b/test/unit/user_event/tab_test.dart index 44f944ce..613f0d54 100644 --- a/test/unit/user_event/tab_test.dart +++ b/test/unit/user_event/tab_test.dart @@ -28,7 +28,7 @@ import '../util/over_react_stubs.dart'; void main() { group('UserEvent.tab events:', () { rtl.RenderResult view; - List inputs; + List/*!*/ inputs; group('', () { setUp(() { diff --git a/test/unit/user_event/type_test.dart b/test/unit/user_event/type_test.dart index 555f5bb7..056f3990 100644 --- a/test/unit/user_event/type_test.dart +++ b/test/unit/user_event/type_test.dart @@ -60,8 +60,8 @@ void main() { } void _typeTestHelper({bool hasDelay = false, bool isTextArea = false}) { - int clickEventCount; - Element element; + int/*!*/ clickEventCount; + Element/*!*/ element; List keyUpCalls; rtl.RenderResult view; diff --git a/test/unit/user_event/upload_test.dart b/test/unit/user_event/upload_test.dart index a7a6582c..22952406 100644 --- a/test/unit/user_event/upload_test.dart +++ b/test/unit/user_event/upload_test.dart @@ -49,10 +49,10 @@ void main() { 'id': 'file-uploader', 'type': 'file', 'onClick': (e) { - clickEventCalls.add((e as react.SyntheticMouseEvent).nativeEvent as MouseEvent); + clickEventCalls.add((e as react.SyntheticMouseEvent).nativeEvent as MouseEvent/*!*/); }, 'onChange': (e) { - changeEventCalls.add((e as react.SyntheticFormEvent).nativeEvent as Event); + changeEventCalls.add((e as react.SyntheticFormEvent).nativeEvent as Event/*!*/); }, 'multiple': isMultiple, 'accept': '.png,.jpeg', diff --git a/test/unit/util/init.dart b/test/unit/util/init.dart index 2e65f958..76b2070c 100644 --- a/test/unit/util/init.dart +++ b/test/unit/util/init.dart @@ -22,7 +22,7 @@ import 'package:test/test.dart'; import 'constants.dart'; void initConfigForInternalTesting([Function() additionalSetup]) { - JsConfig initialConfig; + JsConfig/*!*/ initialConfig; setUpAll(() { initialConfig = rtl.getConfig(); diff --git a/test/unit/util/over_react_stubs.dart b/test/unit/util/over_react_stubs.dart index 7f0896f7..e3294a0c 100644 --- a/test/unit/util/over_react_stubs.dart +++ b/test/unit/util/over_react_stubs.dart @@ -70,6 +70,13 @@ dynamic preparePropsChangeset(ReactElement element, Map newProps, [Iterable newC final type = element.type; final dartComponentVersion = ReactDartComponentVersion.fromType(type); // ignore: invalid_use_of_protected_member + if (newProps == null) { + // Only pre-Component2 Dart components need changesets if props aren't null, + // since the new children need to be stored on the props.internal. + // Otherwise, we can pass `null` straight through to React. + return null; + } + // ignore: invalid_use_of_protected_member if (dartComponentVersion == ReactDartComponentVersion.component2) { // ignore: invalid_use_of_protected_member diff --git a/test/unit/util/rendering.dart b/test/unit/util/rendering.dart index 1ad209ad..5304bfc1 100644 --- a/test/unit/util/rendering.dart +++ b/test/unit/util/rendering.dart @@ -61,7 +61,7 @@ ReactElement elementsForQuerying(String uniqueName, {bool renderMultipleElsMatch {}, react.button({'type': 'button'}, _uniqueName), ), - ) as ReactElement; + ) as ReactElement/*!*/; } renderMultipleElsMatchingQuery ??= false; @@ -71,7 +71,7 @@ ReactElement elementsForQuerying(String uniqueName, {bool renderMultipleElsMatch {}, renderEls(uniqueName), renderEls('2$uniqueName'), - ) as ReactElement; + ) as ReactElement/*!*/; } return renderEls(uniqueName); From afaea6edafc116ac3d7d9927b6923c399f9ef72e Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Fri, 16 Jun 2023 11:05:23 -0500 Subject: [PATCH 03/31] Apply migration --- lib/src/dom/accessibility_helpers.dart | 12 +- lib/src/dom/async/types.dart | 2 +- lib/src/dom/async/wait_for.dart | 48 +-- lib/src/dom/config/configure.dart | 18 +- lib/src/dom/fire_event.dart | 8 +- .../dom/matches/get_default_normalizer.dart | 4 +- lib/src/dom/matches/types.dart | 8 +- lib/src/dom/pretty_dom.dart | 16 +- lib/src/dom/queries/by_alt_text.dart | 44 +-- lib/src/dom/queries/by_display_value.dart | 44 +-- lib/src/dom/queries/by_label_text.dart | 56 ++-- lib/src/dom/queries/by_placeholder_text.dart | 44 +-- lib/src/dom/queries/by_role.dart | 120 ++++---- lib/src/dom/queries/by_testid.dart | 62 ++-- lib/src/dom/queries/by_text.dart | 56 ++-- lib/src/dom/queries/by_title.dart | 44 +-- lib/src/dom/queries/interface.dart | 12 +- lib/src/dom/scoped_queries.dart | 2 +- lib/src/dom/top_level_queries.dart | 276 +++++++++--------- lib/src/dom/within.dart | 12 +- .../matchers/jest_dom/css_class_matchers.dart | 13 +- lib/src/matchers/jest_dom/has_attribute.dart | 2 +- .../matchers/jest_dom/has_description.dart | 6 +- .../matchers/jest_dom/has_form_values.dart | 18 +- lib/src/matchers/jest_dom/has_styles.dart | 10 +- lib/src/matchers/jest_dom/has_value.dart | 4 +- lib/src/matchers/jest_dom/is_checked.dart | 6 +- lib/src/matchers/jest_dom/is_disabled.dart | 2 +- .../jest_dom/is_empty_dom_element.dart | 2 +- lib/src/matchers/jest_dom/is_focused.dart | 2 +- .../matchers/jest_dom/is_in_the_document.dart | 2 +- .../jest_dom/is_partially_checked.dart | 8 +- .../element_text_content_matcher_mixin.dart | 6 +- .../matchers/jest_dom/util/get_value_of.dart | 8 +- lib/src/react/render/render.dart | 16 +- lib/src/react/render/types.dart | 6 +- lib/src/user_event/user_event.dart | 48 +-- lib/src/util/console_log_formatter.dart | 4 +- lib/src/util/console_log_utils.dart | 4 +- lib/src/util/error_message_utils.dart | 6 +- lib/src/util/is_or_contains.dart | 2 +- lib/src/util/js_utils.dart | 6 +- pubspec.yaml | 3 +- test/unit/console_log_utils_test.dart | 4 +- test/unit/dom/accessibility_helpers_test.dart | 10 +- test/unit/dom/fire_event_test.dart | 6 +- .../dom/matchers/css_class_matchers_test.dart | 2 +- .../unit/dom/matchers/has_attribute_test.dart | 2 +- .../dom/matchers/has_description_test.dart | 6 +- .../dom/matchers/has_form_values_test.dart | 4 +- test/unit/dom/matchers/has_styles_test.dart | 6 +- .../dom/matchers/has_text_content_test.dart | 2 +- test/unit/dom/matchers/has_value_test.dart | 4 +- test/unit/dom/matchers/is_focused_test.dart | 4 +- test/unit/dom/pretty_dom_test.dart | 2 +- test/unit/dom/queries/by_label_text_test.dart | 2 +- test/unit/dom/queries/by_role_test.dart | 14 +- test/unit/dom/queries/by_testid_test.dart | 2 +- test/unit/dom/queries/by_text_test.dart | 2 +- .../queries/shared/scoped_queries_tests.dart | 12 +- .../shared/text_match_type_parsing_tests.dart | 50 ++-- test/unit/dom/text_match_test.dart | 2 +- test/unit/dom/top_level_queries_test.dart | 8 +- test/unit/dom/wait_for_test.dart | 30 +- test/unit/dom/within_test.dart | 2 +- test/unit/react/render_test.dart | 28 +- test/unit/user_event/click_test.dart | 8 +- test/unit/user_event/hover_test.dart | 8 +- test/unit/user_event/paste_test.dart | 8 +- test/unit/user_event/select_options_test.dart | 16 +- test/unit/user_event/special_chars_test.dart | 6 +- test/unit/user_event/tab_test.dart | 4 +- test/unit/user_event/type_test.dart | 24 +- test/unit/user_event/upload_test.dart | 26 +- test/unit/util/event_handler_error.dart | 2 +- test/unit/util/init.dart | 6 +- test/unit/util/matchers.dart | 12 +- test/unit/util/over_react_stubs.dart | 4 +- test/unit/util/prints_and_logs_recording.dart | 2 +- test/unit/util/rendering.dart | 10 +- test/unit/util/shadow_dom.dart | 4 +- 81 files changed, 709 insertions(+), 707 deletions(-) diff --git a/lib/src/dom/accessibility_helpers.dart b/lib/src/dom/accessibility_helpers.dart index 1615ba4e..3b20ed35 100644 --- a/lib/src/dom/accessibility_helpers.dart +++ b/lib/src/dom/accessibility_helpers.dart @@ -33,8 +33,8 @@ import 'package:react_testing_library/src/util/console_log_utils.dart'; /// > Learn more: /// /// {@category Accessibility} -Map getRoles(Node container, {bool hidden = false}) => - Map.from(JsBackedMap.fromJs(_getRoles(container, jsifyAndAllowInterop({'hidden': hidden}) as JsMap/*!*/))); +Map getRoles(Node? container, {bool hidden = false}) => + Map.from(JsBackedMap.fromJs(_getRoles(container, jsifyAndAllowInterop({'hidden': hidden}) as JsMap))); /// Prints a list of all the implicit ARIA roles within [container], each role containing a list of all of the /// nodes which match that role. @@ -46,12 +46,12 @@ Map getRoles(Node container, {bool hidden = false}) => /// > Learn more: /// /// {@category Accessibility} -void logRoles(Node container, {bool hidden = false}) => - printConsoleLogs(() => _logRoles(container, jsifyAndAllowInterop({'hidden': hidden}) as JsMap/*!*/)); +void logRoles(Node? container, {bool hidden = false}) => + printConsoleLogs(() => _logRoles(container, jsifyAndAllowInterop({'hidden': hidden}) as JsMap)); @JS('rtl.getRoles') external JsMap _getRoles( - Node container, + Node? container, JsMap options, ); @@ -69,6 +69,6 @@ external bool isInaccessible(Element element); @JS('rtl.logRoles') external JsMap _logRoles( - Node dom, + Node? dom, JsMap options, ); diff --git a/lib/src/dom/async/types.dart b/lib/src/dom/async/types.dart index c9eccba1..4391e20a 100644 --- a/lib/src/dom/async/types.dart +++ b/lib/src/dom/async/types.dart @@ -22,7 +22,7 @@ import 'package:meta/meta.dart'; /// A function typedef used by `onTimeout` parameters in asynchronous `find*` / `waitFor` queries. /// /// Returns either an `Error` or a `TestFailure` when provided with the [originalError]. -typedef QueryTimeoutFn = /*Error || TestFailure*/ Object Function(/*Error*/ Object originalError); +typedef QueryTimeoutFn = /*Error || TestFailure*/ Object? Function(/*Error*/ Object? originalError); @JS() @anonymous diff --git a/lib/src/dom/async/wait_for.dart b/lib/src/dom/async/wait_for.dart index e11f2153..83aef6b9 100644 --- a/lib/src/dom/async/wait_for.dart +++ b/lib/src/dom/async/wait_for.dart @@ -54,11 +54,11 @@ export 'package:react_testing_library/src/dom/async/types.dart' show JsMutationO /// /// {@category Async} Future waitFor( - FutureOr Function() expectation, { - Node container, - Duration timeout, + FutureOr? Function() expectation, { + Node? container, + Duration? timeout, Duration interval = const Duration(milliseconds: 50), - QueryTimeoutFn onTimeout, + QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) async { final config = getConfig(); @@ -67,13 +67,13 @@ Future waitFor( onTimeout ??= (error) => error; /*Error*/ dynamic lastError; - MutationObserver observer; - Timer intervalTimer; - Timer overallTimeoutTimer; + late MutationObserver observer; + late Timer intervalTimer; + late Timer overallTimeoutTimer; var isPending = false; final doneCompleter = Completer(); - void onDone(Object error, T result) { + void onDone(Object? error, T? result) { if (doneCompleter.isCompleted) return; overallTimeoutTimer.cancel(); @@ -94,9 +94,9 @@ Future waitFor( if (lastError != null) { error = lastError; } else { - error = TimeoutException('Timed out in waitFor after ${timeout.inMilliseconds}ms.'); + error = TimeoutException('Timed out in waitFor after ${timeout!.inMilliseconds}ms.'); } - onDone(onTimeout(error), null); + onDone(onTimeout!(error), null); } void checkCallback() { @@ -109,7 +109,7 @@ Future waitFor( .then((resolvedValue) => onDone(null, resolvedValue as T), onError: (e) => lastError = e) .whenComplete(() => isPending = false); } else { - onDone(null, result as T); + onDone(null, result); } // If `callback` throws, wait for the next mutation, interval, or timeout. } catch (error) { @@ -122,7 +122,7 @@ Future waitFor( intervalTimer = Timer.periodic(interval, (_) => checkCallback()); observer = MutationObserver((_, __) => checkCallback()) ..observe( - container, + container!, childList: mutationObserverOptions.childList, attributes: mutationObserverOptions.attributes, characterData: mutationObserverOptions.characterData, @@ -157,11 +157,11 @@ Future waitFor( /// /// {@category Async} Future waitForElementToBeRemoved( - Node/*!*/ Function() callback, { - Node container, - Duration timeout, + Node Function() callback, { + Node? container, + Duration? timeout, Duration interval = const Duration(milliseconds: 50), - QueryTimeoutFn onTimeout, + QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) async { final config = getConfig(); @@ -173,21 +173,21 @@ Future waitForElementToBeRemoved( throw TestingLibraryElementError('The callback must return a non-null Element.'); } - if (!container.contains(el)) { + if (!container!.contains(el)) { throw TestingLibraryElementError( 'The element returned from the callback was not present in the container at the time waitForElementToBeRemoved() was called:\n\n' '${prettyDOM(container)}'); } await waitFor( - () => expect(container.contains(el), isFalse), + () => expect(container!.contains(el), isFalse), container: container, timeout: timeout, interval: interval, onTimeout: onTimeout ?? (error) { return TimeoutException( - 'The element returned from the callback was still present in the container after ${timeout.inMilliseconds}ms:\n\n' + 'The element returned from the callback was still present in the container after ${timeout!.inMilliseconds}ms:\n\n' '${prettyDOM(container)}'); }, mutationObserverOptions: mutationObserverOptions, @@ -214,11 +214,11 @@ Future waitForElementToBeRemoved( /// /// {@category Async} Future waitForElementsToBeRemoved( - List/*!*/ Function() callback, { - Node container, - Duration timeout, + List Function() callback, { + Node? container, + Duration? timeout, Duration interval = const Duration(milliseconds: 50), - QueryTimeoutFn onTimeout, + QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) async { container ??= document.body; @@ -229,7 +229,7 @@ Future waitForElementsToBeRemoved( } for (final el in els) { - if (!container.contains(el)) { + if (!container!.contains(el)) { throw TestingLibraryElementError( 'One of the elements returned from the callback was not present in the container at the time waitForElementsToBeRemoved() was called:\n\n' '${prettyDOM(container)}'); diff --git a/lib/src/dom/config/configure.dart b/lib/src/dom/config/configure.dart index 108e726f..8ca40202 100644 --- a/lib/src/dom/config/configure.dart +++ b/lib/src/dom/config/configure.dart @@ -28,16 +28,16 @@ export 'package:react_testing_library/src/dom/config/types.dart' show JsConfig; /// /// > See: void configure({ - String testIdAttribute, - int asyncUtilTimeout, - bool computedStyleSupportsPseudoElements, - bool defaultHidden, - bool showOriginalStackTrace, - bool throwSuggestions, - TestingLibraryElementError Function(Object message, Element container) getElementError, + String? testIdAttribute, + int? asyncUtilTimeout, + bool? computedStyleSupportsPseudoElements, + bool? defaultHidden, + bool? showOriginalStackTrace, + bool? throwSuggestions, + TestingLibraryElementError Function(Object message, Element container)? getElementError, }) { JsError _getJsGetElementError(Object message, Element container) { - final dartError = allowInterop(getElementError)(message, container); + final dartError = allowInterop(getElementError)!(message, container); return buildJsGetElementError(dartError.message, container); } @@ -54,7 +54,7 @@ void configure({ } @JS('rtl.configure') -external void jsConfigure([JsConfig newConfig]); +external void jsConfigure([JsConfig? newConfig]); /// Returns the configuration options being used by react-testing-library. /// diff --git a/lib/src/dom/fire_event.dart b/lib/src/dom/fire_event.dart index 27891fc5..57fff9d0 100644 --- a/lib/src/dom/fire_event.dart +++ b/lib/src/dom/fire_event.dart @@ -124,19 +124,19 @@ external JsMap get _fireEventObj; /// See: /// /// {@category UserActions} -bool fireEventByName(String eventName, Element element, [Map eventProperties]) { +bool fireEventByName(String eventName, Element element, [Map? eventProperties]) { if (!JsBackedMap.fromJs(_jsEventMap).keys.contains(eventName)) { throw ArgumentError.value(eventName, 'eventName'); } final jsFireEventByNameFn = - JsBackedMap.fromJs(_fireEventObj)[eventName] as bool Function(Element, [/*JsObject*/ dynamic]); + JsBackedMap.fromJs(_fireEventObj)[eventName] as bool Function(Element, [/*JsObject*/ dynamic])?; if (eventProperties == null) { - return eventHandlerErrorCatcher(() => jsFireEventByNameFn(element)); + return eventHandlerErrorCatcher(() => jsFireEventByNameFn!(element)); } - return eventHandlerErrorCatcher(() => jsFireEventByNameFn(element, jsifyAndAllowInterop(eventProperties))); + return eventHandlerErrorCatcher(() => jsFireEventByNameFn!(element, jsifyAndAllowInterop(eventProperties))); } @JS('rtl.eventMap') diff --git a/lib/src/dom/matches/get_default_normalizer.dart b/lib/src/dom/matches/get_default_normalizer.dart index 9efcfc1d..edde3562 100644 --- a/lib/src/dom/matches/get_default_normalizer.dart +++ b/lib/src/dom/matches/get_default_normalizer.dart @@ -25,11 +25,11 @@ import 'package:react_testing_library/src/dom/matches/types.dart'; /// multiple adjacent whitespace characters into a single space. /// /// > See: -NormalizerFn Function([NormalizerOptions]) getDefaultNormalizer([NormalizerOptions options]) { +NormalizerFn Function([NormalizerOptions?]) getDefaultNormalizer([NormalizerOptions? options]) { return _jsGetDefaultNormalizer(NormalizerOptions() ..trim = options?.trim ?? true ..collapseWhitespace = options?.collapseWhitespace ?? true); } @JS('rtl.getDefaultNormalizer') -external NormalizerFn Function([NormalizerOptions]) _jsGetDefaultNormalizer([NormalizerOptions options]); +external NormalizerFn Function([NormalizerOptions?]) _jsGetDefaultNormalizer([NormalizerOptions? options]); diff --git a/lib/src/dom/matches/types.dart b/lib/src/dom/matches/types.dart index a903da84..48954bb2 100644 --- a/lib/src/dom/matches/types.dart +++ b/lib/src/dom/matches/types.dart @@ -82,17 +82,17 @@ abstract class TextMatch { return (originalMessage, container) { final newMessage = originalMessage.toString().replaceAllMapped(dartInteropFunctionValueRegex, (match) { - final optionalOpeningQuoteOrBacktick = match.group(1); + final optionalOpeningQuoteOrBacktick = match.group(1)!; final optionalClosingQuoteOrBacktick = match.group(3); final newValueLines = newValue.toString().split('\n'); var restOfMessageBeforePrettyDomOrAccessibleRolesPrintout = match.group(4); if (newValueLines.length > 1) { // Prevent the first sentence after the multiline function signature from starting with " . ". restOfMessageBeforePrettyDomOrAccessibleRolesPrintout = - restOfMessageBeforePrettyDomOrAccessibleRolesPrintout.replaceFirst(RegExp(r'^\s*\.*\s*'), ''); + restOfMessageBeforePrettyDomOrAccessibleRolesPrintout!.replaceFirst(RegExp(r'^\s*\.*\s*'), ''); } var returnValue = '${newValueLines.join('\n')}$restOfMessageBeforePrettyDomOrAccessibleRolesPrintout'; - if (optionalOpeningQuoteOrBacktick.isNotEmpty || optionalClosingQuoteOrBacktick.isNotEmpty) { + if (optionalOpeningQuoteOrBacktick.isNotEmpty || optionalClosingQuoteOrBacktick!.isNotEmpty) { // Restore quotes around the function/regexp portion of the new value if they were previously found around // the `function...` dart interop portion of the original message. returnValue = returnValue.replaceAllMapped( @@ -188,4 +188,4 @@ class NormalizerOptions { } /// The function signature for a custom `normalizer` argument in a query. -typedef NormalizerFn = String Function(String); +typedef NormalizerFn = String Function(String?); diff --git a/lib/src/dom/pretty_dom.dart b/lib/src/dom/pretty_dom.dart index ef505bb3..a0409e8b 100644 --- a/lib/src/dom/pretty_dom.dart +++ b/lib/src/dom/pretty_dom.dart @@ -53,11 +53,11 @@ import 'package:js/js.dart'; /// /// See the [JS `prettyDOM` docs](https://testing-library.com/docs/dom-testing-library/api-debugging/#prettydom) for more details and examples. String prettyDOM( - Node node, { - int maxLength, - int indent, - int maxDepth, - bool min, + Node? node, { + int? maxLength, + int? indent, + int? maxDepth, + bool? min, }) { final options = PrettyDomOptions(); if (indent != null) options.indent = indent; @@ -69,9 +69,9 @@ String prettyDOM( @JS('rtl.prettyDOM') external String _jsPrettyDOM([ - Node dom, - int maxLength, - PrettyDomOptions options, + Node? dom, + int? maxLength, + PrettyDomOptions? options, ]); /// A subset of diff --git a/lib/src/dom/queries/by_alt_text.dart b/lib/src/dom/queries/by_alt_text.dart index 11847779..6945cde1 100644 --- a/lib/src/dom/queries/by_alt_text.dart +++ b/lib/src/dom/queries/by_alt_text.dart @@ -93,7 +93,7 @@ mixin ByAltTextQueries on IQueries { E getByAltText( /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => withErrorInterop( () => _jsGetByAltText( @@ -127,7 +127,7 @@ mixin ByAltTextQueries on IQueries { List getAllByAltText( /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => withErrorInterop( () => _jsGetAllByAltText( @@ -161,7 +161,7 @@ mixin ByAltTextQueries on IQueries { E queryByAltText( /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => _jsQueryByAltText( getContainerForScope(), @@ -193,7 +193,7 @@ mixin ByAltTextQueries on IQueries { List queryAllByAltText( /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => _jsQueryAllByAltText( getContainerForScope(), @@ -235,11 +235,11 @@ mixin ByAltTextQueries on IQueries { Future findByAltText( /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, - MutationObserverOptions mutationObserverOptions, + NormalizerFn Function([NormalizerOptions?])? normalizer, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, + MutationObserverOptions? mutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getByAltText` instead of an // interop like `_jsFindByAltText` to give consumers better async stack traces. @@ -291,11 +291,11 @@ mixin ByAltTextQueries on IQueries { Future> findAllByAltText( /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, - MutationObserverOptions mutationObserverOptions, + NormalizerFn Function([NormalizerOptions?])? normalizer, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, + MutationObserverOptions? mutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getAllByAltText` instead of an // interop like `_jsFindAllByAltText` to give consumers better async stack traces. @@ -316,28 +316,28 @@ mixin ByAltTextQueries on IQueries { @JS('rtl.getByAltText') external Element _jsGetByAltText( - Node container, + Node? container, /*TextMatch*/ dynamic text, [ - MatcherOptions options, + MatcherOptions? options, ]); @JS('rtl.getAllByAltText') external List< /*Element*/ dynamic> _jsGetAllByAltText( - Node container, + Node? container, /*TextMatch*/ dynamic text, [ - MatcherOptions options, + MatcherOptions? options, ]); @JS('rtl.queryByAltText') external Element _jsQueryByAltText( - Node container, + Node? container, /*TextMatch*/ dynamic text, [ - MatcherOptions options, + MatcherOptions? options, ]); @JS('rtl.queryAllByAltText') external List< /*Element*/ dynamic> _jsQueryAllByAltText( - Node container, + Node? container, /*TextMatch*/ dynamic text, [ - MatcherOptions options, + MatcherOptions? options, ]); diff --git a/lib/src/dom/queries/by_display_value.dart b/lib/src/dom/queries/by_display_value.dart index 4ac7d34b..6f8828b2 100644 --- a/lib/src/dom/queries/by_display_value.dart +++ b/lib/src/dom/queries/by_display_value.dart @@ -119,7 +119,7 @@ mixin ByDisplayValueQueries on IQueries { E getByDisplayValue( /*TextMatch*/ dynamic value, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => withErrorInterop( () => _jsGetByDisplayValue( @@ -153,7 +153,7 @@ mixin ByDisplayValueQueries on IQueries { List getAllByDisplayValue( /*TextMatch*/ dynamic value, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => withErrorInterop( () => _jsGetAllByDisplayValue( @@ -187,7 +187,7 @@ mixin ByDisplayValueQueries on IQueries { E queryByDisplayValue( /*TextMatch*/ dynamic value, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => _jsQueryByDisplayValue( getContainerForScope(), @@ -219,7 +219,7 @@ mixin ByDisplayValueQueries on IQueries { List queryAllByDisplayValue( /*TextMatch*/ dynamic value, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => _jsQueryAllByDisplayValue( getContainerForScope(), @@ -260,11 +260,11 @@ mixin ByDisplayValueQueries on IQueries { Future findByDisplayValue( /*TextMatch*/ dynamic value, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, - MutationObserverOptions mutationObserverOptions, + NormalizerFn Function([NormalizerOptions?])? normalizer, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, + MutationObserverOptions? mutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getByDisplayValue` instead of an // interop like `_jsFindByDisplayValue` to give consumers better async stack traces. @@ -315,11 +315,11 @@ mixin ByDisplayValueQueries on IQueries { Future> findAllByDisplayValue( /*TextMatch*/ dynamic value, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, - MutationObserverOptions mutationObserverOptions, + NormalizerFn Function([NormalizerOptions?])? normalizer, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, + MutationObserverOptions? mutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getAllByDisplayValue` instead of an // interop like `_jsFindAllByDisplayValue` to give consumers better async stack traces. @@ -340,28 +340,28 @@ mixin ByDisplayValueQueries on IQueries { @JS('rtl.getByDisplayValue') external Element _jsGetByDisplayValue( - Node container, + Node? container, /*TextMatch*/ dynamic value, [ - MatcherOptions options, + MatcherOptions? options, ]); @JS('rtl.getAllByDisplayValue') external List< /*Element*/ dynamic> _jsGetAllByDisplayValue( - Node container, + Node? container, /*TextMatch*/ dynamic value, [ - MatcherOptions options, + MatcherOptions? options, ]); @JS('rtl.queryByDisplayValue') external Element _jsQueryByDisplayValue( - Node container, + Node? container, /*TextMatch*/ dynamic value, [ - MatcherOptions options, + MatcherOptions? options, ]); @JS('rtl.queryAllByDisplayValue') external List< /*Element*/ dynamic> _jsQueryAllByDisplayValue( - Node container, + Node? container, /*TextMatch*/ dynamic value, [ - MatcherOptions options, + MatcherOptions? options, ]); diff --git a/lib/src/dom/queries/by_label_text.dart b/lib/src/dom/queries/by_label_text.dart index 1b941228..07a23446 100644 --- a/lib/src/dom/queries/by_label_text.dart +++ b/lib/src/dom/queries/by_label_text.dart @@ -111,8 +111,8 @@ mixin ByLabelTextQueries on IQueries { E getByLabelText( /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - String selector, + NormalizerFn Function([NormalizerOptions?])? normalizer, + String? selector, }) => withErrorInterop( () => _jsGetByLabelText( @@ -145,8 +145,8 @@ mixin ByLabelTextQueries on IQueries { List getAllByLabelText( /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - String selector, + NormalizerFn Function([NormalizerOptions?])? normalizer, + String? selector, }) => withErrorInterop( () => _jsGetAllByLabelText( @@ -179,8 +179,8 @@ mixin ByLabelTextQueries on IQueries { E queryByLabelText( /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - String selector, + NormalizerFn Function([NormalizerOptions?])? normalizer, + String? selector, }) => _jsQueryByLabelText( getContainerForScope(), @@ -211,8 +211,8 @@ mixin ByLabelTextQueries on IQueries { List queryAllByLabelText( /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - String selector, + NormalizerFn Function([NormalizerOptions?])? normalizer, + String? selector, }) => _jsQueryAllByLabelText( getContainerForScope(), @@ -252,12 +252,12 @@ mixin ByLabelTextQueries on IQueries { Future findByLabelText( /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - String selector, - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, - MutationObserverOptions mutationObserverOptions, + NormalizerFn Function([NormalizerOptions?])? normalizer, + String? selector, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, + MutationObserverOptions? mutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getByLabelText` instead of an // interop like `_jsFindByLabelText` to give consumers better async stack traces. @@ -308,12 +308,12 @@ mixin ByLabelTextQueries on IQueries { Future> findAllByLabelText( /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - String selector, - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, - MutationObserverOptions mutationObserverOptions, + NormalizerFn Function([NormalizerOptions?])? normalizer, + String? selector, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, + MutationObserverOptions? mutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getAllByAltText` instead of an // interop like `_jsFindAllByAltText` to give consumers better async stack traces. @@ -335,28 +335,28 @@ mixin ByLabelTextQueries on IQueries { @JS('rtl.getByLabelText') external Element _jsGetByLabelText( - Node container, + Node? container, /*TextMatch*/ dynamic text, [ - MatcherOptions options, + MatcherOptions? options, ]); @JS('rtl.getAllByLabelText') external List< /*Element*/ dynamic> _jsGetAllByLabelText( - Node container, + Node? container, /*TextMatch*/ dynamic text, [ - MatcherOptions options, + MatcherOptions? options, ]); @JS('rtl.queryByLabelText') external Element _jsQueryByLabelText( - Node container, + Node? container, /*TextMatch*/ dynamic text, [ - MatcherOptions options, + MatcherOptions? options, ]); @JS('rtl.queryAllByLabelText') external List< /*Element*/ dynamic> _jsQueryAllByLabelText( - Node container, + Node? container, /*TextMatch*/ dynamic text, [ - MatcherOptions options, + MatcherOptions? options, ]); diff --git a/lib/src/dom/queries/by_placeholder_text.dart b/lib/src/dom/queries/by_placeholder_text.dart index eaa5bdc9..08d7590c 100644 --- a/lib/src/dom/queries/by_placeholder_text.dart +++ b/lib/src/dom/queries/by_placeholder_text.dart @@ -89,7 +89,7 @@ mixin ByPlaceholderTextQueries on IQueries { E getByPlaceholderText( /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => withErrorInterop( () => _jsGetByPlaceholderText( @@ -123,7 +123,7 @@ mixin ByPlaceholderTextQueries on IQueries { List getAllByPlaceholderText( /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => withErrorInterop( () => _jsGetAllByPlaceholderText( @@ -157,7 +157,7 @@ mixin ByPlaceholderTextQueries on IQueries { E queryByPlaceholderText( /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => _jsQueryByPlaceholderText( getContainerForScope(), @@ -189,7 +189,7 @@ mixin ByPlaceholderTextQueries on IQueries { List queryAllByPlaceholderText( /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => _jsQueryAllByPlaceholderText( getContainerForScope(), @@ -230,11 +230,11 @@ mixin ByPlaceholderTextQueries on IQueries { Future findByPlaceholderText( /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, - MutationObserverOptions mutationObserverOptions, + NormalizerFn Function([NormalizerOptions?])? normalizer, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, + MutationObserverOptions? mutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getByPlaceholderText` instead of an // interop like `_jsFindByPlaceholderText` to give consumers better async stack traces. @@ -285,11 +285,11 @@ mixin ByPlaceholderTextQueries on IQueries { Future> findAllByPlaceholderText( /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, - MutationObserverOptions mutationObserverOptions, + NormalizerFn Function([NormalizerOptions?])? normalizer, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, + MutationObserverOptions? mutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getAllByPlaceholderText` instead of an // interop like `_jsFindAllByPlaceholderText` to give consumers better async stack traces. @@ -310,28 +310,28 @@ mixin ByPlaceholderTextQueries on IQueries { @JS('rtl.getByPlaceholderText') external Element _jsGetByPlaceholderText( - Node container, + Node? container, /*TextMatch*/ dynamic text, [ - MatcherOptions options, + MatcherOptions? options, ]); @JS('rtl.getAllByPlaceholderText') external List< /*Element*/ dynamic> _jsGetAllByPlaceholderText( - Node container, + Node? container, /*TextMatch*/ dynamic text, [ - MatcherOptions options, + MatcherOptions? options, ]); @JS('rtl.queryByPlaceholderText') external Element _jsQueryByPlaceholderText( - Node container, + Node? container, /*TextMatch*/ dynamic text, [ - MatcherOptions options, + MatcherOptions? options, ]); @JS('rtl.queryAllByPlaceholderText') external List< /*Element*/ dynamic> _jsQueryAllByPlaceholderText( - Node container, + Node? container, /*TextMatch*/ dynamic text, [ - MatcherOptions options, + MatcherOptions? options, ]); diff --git a/lib/src/dom/queries/by_role.dart b/lib/src/dom/queries/by_role.dart index 4055dac7..e9e2f3e5 100644 --- a/lib/src/dom/queries/by_role.dart +++ b/lib/src/dom/queries/by_role.dart @@ -38,15 +38,15 @@ mixin ByRoleQueries on IQueries { @protected ByRoleOptions buildByRoleOptions({ bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, bool hidden = false, /*TextMatch*/ dynamic name, - bool selected, - bool checked, - bool pressed, - bool expanded, + bool? selected, + bool? checked, + bool? pressed, + bool? expanded, bool queryFallbacks = false, - int level, + int? level, }) { final byRoleOptions = ByRoleOptions() ..exact = exact @@ -125,15 +125,15 @@ mixin ByRoleQueries on IQueries { E getByRole( /*TextMatch*/ dynamic role, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, bool hidden = false, /*TextMatch*/ dynamic name, - bool selected, - bool checked, - bool pressed, - bool expanded, + bool? selected, + bool? checked, + bool? pressed, + bool? expanded, bool queryFallbacks = false, - int level, + int? level, }) => withErrorInterop( () => _jsGetByRole( @@ -183,15 +183,15 @@ mixin ByRoleQueries on IQueries { List getAllByRole( /*TextMatch*/ dynamic role, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, bool hidden = false, /*TextMatch*/ dynamic name, - bool selected, - bool checked, - bool pressed, - bool expanded, + bool? selected, + bool? checked, + bool? pressed, + bool? expanded, bool queryFallbacks = false, - int level, + int? level, }) => withErrorInterop( () => _jsGetAllByRole( @@ -241,15 +241,15 @@ mixin ByRoleQueries on IQueries { E queryByRole( /*TextMatch*/ dynamic role, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, bool hidden = false, /*TextMatch*/ dynamic name, - bool selected, - bool checked, - bool pressed, - bool expanded, + bool? selected, + bool? checked, + bool? pressed, + bool? expanded, bool queryFallbacks = false, - int level, + int? level, }) => _jsQueryByRole( getContainerForScope(), @@ -298,15 +298,15 @@ mixin ByRoleQueries on IQueries { List queryAllByRole( /*TextMatch*/ dynamic role, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, bool hidden = false, /*TextMatch*/ dynamic name, - bool selected, - bool checked, - bool pressed, - bool expanded, + bool? selected, + bool? checked, + bool? pressed, + bool? expanded, bool queryFallbacks = false, - int level, + int? level, }) => _jsQueryAllByRole( getContainerForScope(), @@ -365,19 +365,19 @@ mixin ByRoleQueries on IQueries { Future findByRole( /*TextMatch*/ dynamic role, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, bool hidden = false, /*TextMatch*/ dynamic name, - bool selected, - bool checked, - bool pressed, - bool expanded, + bool? selected, + bool? checked, + bool? pressed, + bool? expanded, bool queryFallbacks = false, - int level, - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, - MutationObserverOptions mutationObserverOptions, + int? level, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, + MutationObserverOptions? mutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getByRole` instead of an // interop like `_jsFindByRole` to give consumers better async stack traces. @@ -443,19 +443,19 @@ mixin ByRoleQueries on IQueries { Future> findAllByRole( /*TextMatch*/ dynamic role, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, bool hidden = false, /*TextMatch*/ dynamic name, - bool selected, - bool checked, - bool pressed, - bool expanded, + bool? selected, + bool? checked, + bool? pressed, + bool? expanded, bool queryFallbacks = false, - int level, - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, - MutationObserverOptions mutationObserverOptions, + int? level, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, + MutationObserverOptions? mutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getAllByRole` instead of an // interop like `_jsFindAllByRole` to give consumers better async stack traces. @@ -484,30 +484,30 @@ mixin ByRoleQueries on IQueries { @JS('rtl.getByRole') external Element _jsGetByRole( - Node container, + Node? container, /*TextMatch*/ dynamic role, [ - ByRoleOptions options, + ByRoleOptions? options, ]); @JS('rtl.getAllByRole') external List< /*Element*/ dynamic> _jsGetAllByRole( - Node container, + Node? container, /*TextMatch*/ dynamic role, [ - ByRoleOptions options, + ByRoleOptions? options, ]); @JS('rtl.queryByRole') external Element _jsQueryByRole( - Node container, + Node? container, /*TextMatch*/ dynamic role, [ - ByRoleOptions options, + ByRoleOptions? options, ]); @JS('rtl.queryAllByRole') external List< /*Element*/ dynamic> _jsQueryAllByRole( - Node container, + Node? container, /*TextMatch*/ dynamic role, [ - ByRoleOptions options, + ByRoleOptions? options, ]); @JS() @@ -516,8 +516,8 @@ class ByRoleOptions { external bool get exact; external set exact(bool value); - external NormalizerFn Function([NormalizerOptions]) get normalizer; - external set normalizer(NormalizerFn Function([NormalizerOptions]) value); + external NormalizerFn Function([NormalizerOptions?]) get normalizer; + external set normalizer(NormalizerFn Function([NormalizerOptions?]) value); /// {@template byRoleOptionsName} /// You can also query the returned element(s) by their [accessible name](https://www.w3.org/TR/accname-1.1/) diff --git a/lib/src/dom/queries/by_testid.dart b/lib/src/dom/queries/by_testid.dart index 247ee61c..c8d866f4 100644 --- a/lib/src/dom/queries/by_testid.dart +++ b/lib/src/dom/queries/by_testid.dart @@ -102,7 +102,7 @@ mixin ByTestIdQueries on IQueries { E getByTestId( /*TextMatch*/ dynamic testId, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) { E jsQuery(dynamic testIdTextMatchValue) { return withErrorInterop( @@ -125,7 +125,7 @@ mixin ByTestIdQueries on IQueries { // Replace regex produced by `_convertTestIdStringToRegExp` in the error message with the string provided // by the consumer since that is how they authored it. throw _errorWithMessageUsingStringTestIdProvided( - errorThrownUsingRegExTestIdValue: e, stackTrace: st, testId: testId as String); + errorThrownUsingRegExTestIdValue: e, stackTrace: st, testId: testId); } else { rethrow; } @@ -156,7 +156,7 @@ mixin ByTestIdQueries on IQueries { List getAllByTestId( /*TextMatch*/ dynamic testId, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) { List jsQuery(dynamic testIdTextMatchValue) { return withErrorInterop( @@ -179,7 +179,7 @@ mixin ByTestIdQueries on IQueries { // Replace regex produced by `_convertTestIdStringToRegExp` in the error message with the string provided // by the consumer since that is how they authored it. throw _errorWithMessageUsingStringTestIdProvided( - errorThrownUsingRegExTestIdValue: e, stackTrace: st, testId: testId as String); + errorThrownUsingRegExTestIdValue: e, stackTrace: st, testId: testId); } else { rethrow; } @@ -210,7 +210,7 @@ mixin ByTestIdQueries on IQueries { E queryByTestId( /*TextMatch*/ dynamic testId, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) { // For strings, we need to jump through a few more hoops to ensure that we support matching a single // test id value on an element that may have more than one. @@ -235,7 +235,7 @@ mixin ByTestIdQueries on IQueries { // Replace regex produced by `_convertTestIdStringToRegExp` in the error message with the string provided // by the consumer since that is how they authored it. throw _errorWithMessageUsingStringTestIdProvided( - errorThrownUsingRegExTestIdValue: e, stackTrace: st, testId: testId as String); + errorThrownUsingRegExTestIdValue: e, stackTrace: st, testId: testId); } else { rethrow; } @@ -266,7 +266,7 @@ mixin ByTestIdQueries on IQueries { List queryAllByTestId( /*TextMatch*/ dynamic testId, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) { // For strings, we need to jump through a few more hoops to ensure that we support matching a single // test id value on an element that may have more than one. @@ -291,7 +291,7 @@ mixin ByTestIdQueries on IQueries { // Replace regex produced by `_convertTestIdStringToRegExp` in the error message with the string provided // by the consumer since that is how they authored it. throw _errorWithMessageUsingStringTestIdProvided( - errorThrownUsingRegExTestIdValue: e, stackTrace: st, testId: testId as String); + errorThrownUsingRegExTestIdValue: e, stackTrace: st, testId: testId); } else { rethrow; } @@ -331,11 +331,11 @@ mixin ByTestIdQueries on IQueries { Future findByTestId( /*TextMatch*/ dynamic testId, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, - MutationObserverOptions mutationObserverOptions, + NormalizerFn Function([NormalizerOptions?])? normalizer, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, + MutationObserverOptions? mutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getByTestId` instead of an // interop like `_jsFindByTestId` to give consumers better async stack traces. @@ -386,11 +386,11 @@ mixin ByTestIdQueries on IQueries { Future> findAllByTestId( /*TextMatch*/ dynamic testId, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, - MutationObserverOptions mutationObserverOptions, + NormalizerFn Function([NormalizerOptions?])? normalizer, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, + MutationObserverOptions? mutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getAllByTestId` instead of an // interop like `_jsFindAllByTestId` to give consumers better async stack traces. @@ -411,30 +411,30 @@ mixin ByTestIdQueries on IQueries { @JS('rtl.getByTestId') external Element _jsGetByTestId( - Node container, + Node? container, /*TextMatch*/ dynamic testId, [ - MatcherOptions options, + MatcherOptions? options, ]); @JS('rtl.getAllByTestId') external List< /*Element*/ dynamic> _jsGetAllByTestId( - Node container, + Node? container, /*TextMatch*/ dynamic testId, [ - MatcherOptions options, + MatcherOptions? options, ]); @JS('rtl.queryByTestId') external Element _jsQueryByTestId( - Node container, + Node? container, /*TextMatch*/ dynamic testId, [ - MatcherOptions options, + MatcherOptions? options, ]); @JS('rtl.queryAllByTestId') external List< /*Element*/ dynamic> _jsQueryAllByTestId( - Node container, + Node? container, /*TextMatch*/ dynamic testId, [ - MatcherOptions options, + MatcherOptions? options, ]); /// Converts string [testId] values into a `RegExp` that matches whole words within a value that may contain one or @@ -445,8 +445,8 @@ dynamic _convertTestIdStringToRegExp(dynamic testId, {bool exact = true}) { if (testId is! String) return TextMatch.toJs(testId); final testIdMatcher = exact - ? RegExp('(\\s|^)${RegExp.escape(testId as String)}(\\s|\$)') - : RegExp('(.?)${RegExp.escape(testId as String)}(.?)', caseSensitive: false); + ? RegExp('(\\s|^)${RegExp.escape(testId)}(\\s|\$)') + : RegExp('(.?)${RegExp.escape(testId)}(.?)', caseSensitive: false); return TextMatch.toJs(testIdMatcher); } @@ -455,9 +455,9 @@ dynamic _convertTestIdStringToRegExp(dynamic testId, {bool exact = true}) { /// the consumer in its message so that the implementation details of our [_convertTestIdStringToRegExp] `RegExp` /// workaround are completely opaque to the consumer. TestingLibraryElementError _errorWithMessageUsingStringTestIdProvided({ - @required TestingLibraryElementError errorThrownUsingRegExTestIdValue, - @required StackTrace stackTrace, - @required String testId, + required TestingLibraryElementError errorThrownUsingRegExTestIdValue, + required StackTrace stackTrace, + required String testId, }) { final messageUsingTestIdProvidedByUser = errorThrownUsingRegExTestIdValue.message.replaceAllMapped(RegExp(r'\[(.*)="RegExp\/(.*)\/".?\]'), (match) { diff --git a/lib/src/dom/queries/by_text.dart b/lib/src/dom/queries/by_text.dart index 54de2afb..239d597b 100644 --- a/lib/src/dom/queries/by_text.dart +++ b/lib/src/dom/queries/by_text.dart @@ -95,8 +95,8 @@ mixin ByTextQueries on IQueries { E getByText( /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - String selector, + NormalizerFn Function([NormalizerOptions?])? normalizer, + String? selector, /*String|bool*/ dynamic ignore = 'script', }) => withErrorInterop( @@ -132,8 +132,8 @@ mixin ByTextQueries on IQueries { List getAllByText( /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - String selector, + NormalizerFn Function([NormalizerOptions?])? normalizer, + String? selector, /*String|bool*/ dynamic ignore = 'script', }) => withErrorInterop( @@ -169,8 +169,8 @@ mixin ByTextQueries on IQueries { E queryByText( /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - String selector, + NormalizerFn Function([NormalizerOptions?])? normalizer, + String? selector, /*String|bool*/ dynamic ignore = 'script', }) => _jsQueryByText( @@ -204,8 +204,8 @@ mixin ByTextQueries on IQueries { List queryAllByText( /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - String selector, + NormalizerFn Function([NormalizerOptions?])? normalizer, + String? selector, /*String|bool*/ dynamic ignore = 'script', }) => _jsQueryAllByText( @@ -249,13 +249,13 @@ mixin ByTextQueries on IQueries { Future findByText( /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - String selector, + NormalizerFn Function([NormalizerOptions?])? normalizer, + String? selector, /*String|bool*/ dynamic ignore = 'script', - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, - MutationObserverOptions mutationObserverOptions, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, + MutationObserverOptions? mutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getByText` instead of an // interop like `_jsFindByText` to give consumers better async stack traces. @@ -310,13 +310,13 @@ mixin ByTextQueries on IQueries { Future> findAllByText( /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - String selector, + NormalizerFn Function([NormalizerOptions?])? normalizer, + String? selector, /*String|bool*/ dynamic ignore = 'script', - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, - MutationObserverOptions mutationObserverOptions, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, + MutationObserverOptions? mutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getAllByText` instead of an // interop like `_jsFindAllByText` to give consumers better async stack traces. @@ -339,28 +339,28 @@ mixin ByTextQueries on IQueries { @JS('rtl.getByText') external Element _jsGetByText( - Node container, + Node? container, /*TextMatch*/ dynamic text, [ - MatcherOptions options, + MatcherOptions? options, ]); @JS('rtl.getAllByText') external List< /*Element*/ dynamic> _jsGetAllByText( - Node container, + Node? container, /*TextMatch*/ dynamic text, [ - MatcherOptions options, + MatcherOptions? options, ]); @JS('rtl.queryByText') external Element _jsQueryByText( - Node container, + Node? container, /*TextMatch*/ dynamic text, [ - MatcherOptions options, + MatcherOptions? options, ]); @JS('rtl.queryAllByText') external List< /*Element*/ dynamic> _jsQueryAllByText( - Node container, + Node? container, /*TextMatch*/ dynamic text, [ - MatcherOptions options, + MatcherOptions? options, ]); diff --git a/lib/src/dom/queries/by_title.dart b/lib/src/dom/queries/by_title.dart index a14ffc2e..0e38de15 100644 --- a/lib/src/dom/queries/by_title.dart +++ b/lib/src/dom/queries/by_title.dart @@ -98,7 +98,7 @@ mixin ByTitleQueries on IQueries { E getByTitle( /*TextMatch*/ dynamic title, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => withErrorInterop( () => _jsGetByTitle( @@ -132,7 +132,7 @@ mixin ByTitleQueries on IQueries { List getAllByTitle( /*TextMatch*/ dynamic title, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => withErrorInterop( () => _jsGetAllByTitle( @@ -166,7 +166,7 @@ mixin ByTitleQueries on IQueries { E queryByTitle( /*TextMatch*/ dynamic title, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => _jsQueryByTitle( getContainerForScope(), @@ -198,7 +198,7 @@ mixin ByTitleQueries on IQueries { List queryAllByTitle( /*TextMatch*/ dynamic title, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => _jsQueryAllByTitle( getContainerForScope(), @@ -239,11 +239,11 @@ mixin ByTitleQueries on IQueries { Future findByTitle( /*TextMatch*/ dynamic title, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, - MutationObserverOptions mutationObserverOptions, + NormalizerFn Function([NormalizerOptions?])? normalizer, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, + MutationObserverOptions? mutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getByTitle` instead of an // interop like `_jsFindByTitle` to give consumers better async stack traces. @@ -294,11 +294,11 @@ mixin ByTitleQueries on IQueries { Future> findAllByTitle( /*TextMatch*/ dynamic title, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, - MutationObserverOptions mutationObserverOptions, + NormalizerFn Function([NormalizerOptions?])? normalizer, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, + MutationObserverOptions? mutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getAllByTitle` instead of an // interop like `_jsFindAllByTitle` to give consumers better async stack traces. @@ -319,28 +319,28 @@ mixin ByTitleQueries on IQueries { @JS('rtl.getByTitle') external Element _jsGetByTitle( - Node container, + Node? container, /*TextMatch*/ dynamic title, [ - MatcherOptions options, + MatcherOptions? options, ]); @JS('rtl.getAllByTitle') external List< /*Element*/ dynamic> _jsGetAllByTitle( - Node container, + Node? container, /*TextMatch*/ dynamic title, [ - MatcherOptions options, + MatcherOptions? options, ]); @JS('rtl.queryByTitle') external Element _jsQueryByTitle( - Node container, + Node? container, /*TextMatch*/ dynamic title, [ - MatcherOptions options, + MatcherOptions? options, ]); @JS('rtl.queryAllByTitle') external List< /*Element*/ dynamic> _jsQueryAllByTitle( - Node container, + Node? container, /*TextMatch*/ dynamic title, [ - MatcherOptions options, + MatcherOptions? options, ]); diff --git a/lib/src/dom/queries/interface.dart b/lib/src/dom/queries/interface.dart index 4b13cf37..84fca9eb 100644 --- a/lib/src/dom/queries/interface.dart +++ b/lib/src/dom/queries/interface.dart @@ -24,14 +24,14 @@ import 'package:react_testing_library/src/dom/matches/types.dart'; mixin IQueries { /// @nodoc @protected - Node Function() get getContainerForScope; + Node? Function() get getContainerForScope; /// @nodoc @protected MatcherOptions buildMatcherOptions({ bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - String selector, + NormalizerFn Function([NormalizerOptions?])? normalizer, + String? selector, /*String|bool*/ dynamic ignore = 'script', }) { final matcherOptions = MatcherOptions()..exact = exact; @@ -45,9 +45,9 @@ mixin IQueries { /// @nodoc @protected SharedJsWaitForOptions buildWaitForOptions({ - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) { final waitForOptions = SharedJsWaitForOptions(); diff --git a/lib/src/dom/scoped_queries.dart b/lib/src/dom/scoped_queries.dart index ebd5f0d8..9fa68959 100644 --- a/lib/src/dom/scoped_queries.dart +++ b/lib/src/dom/scoped_queries.dart @@ -46,5 +46,5 @@ abstract class ScopedQueries /// @nodoc @protected @override - final Node Function() getContainerForScope; + final Node? Function() getContainerForScope; } diff --git a/lib/src/dom/top_level_queries.dart b/lib/src/dom/top_level_queries.dart index 9df9ffda..36b312c1 100644 --- a/lib/src/dom/top_level_queries.dart +++ b/lib/src/dom/top_level_queries.dart @@ -53,7 +53,7 @@ E getByAltText( Node container, /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => within(container).getByAltText(text, exact: exact, normalizer: normalizer); @@ -85,7 +85,7 @@ List getAllByAltText( Node container, /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => within(container).getAllByAltText(text, exact: exact, normalizer: normalizer); @@ -117,7 +117,7 @@ E queryByAltText( Node container, /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => within(container).queryByAltText(text, exact: exact, normalizer: normalizer); @@ -149,7 +149,7 @@ List queryAllByAltText( Node container, /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => within(container).queryAllByAltText(text, exact: exact, normalizer: normalizer); @@ -192,10 +192,10 @@ Future findByAltText( Node container, /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, + NormalizerFn Function([NormalizerOptions?])? normalizer, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => within(container).findByAltText(text, @@ -245,10 +245,10 @@ Future> findAllByAltText( Node container, /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, + NormalizerFn Function([NormalizerOptions?])? normalizer, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => within(container).findAllByAltText(text, @@ -291,7 +291,7 @@ E getByDisplayValue( Node container, /*TextMatch*/ dynamic value, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => within(container).getByDisplayValue(value, exact: exact, normalizer: normalizer); @@ -323,7 +323,7 @@ List getAllByDisplayValue( Node container, /*TextMatch*/ dynamic value, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => within(container).getAllByDisplayValue(value, exact: exact, normalizer: normalizer); @@ -355,7 +355,7 @@ E queryByDisplayValue( Node container, /*TextMatch*/ dynamic value, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => within(container).queryByDisplayValue(value, exact: exact, normalizer: normalizer); @@ -387,7 +387,7 @@ List queryAllByDisplayValue( Node container, /*TextMatch*/ dynamic value, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => within(container).queryAllByDisplayValue(value, exact: exact, normalizer: normalizer); @@ -429,10 +429,10 @@ Future findByDisplayValue( Node container, /*TextMatch*/ dynamic value, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, + NormalizerFn Function([NormalizerOptions?])? normalizer, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => within(container).findByDisplayValue(value, @@ -481,10 +481,10 @@ Future> findAllByDisplayValue( Node container, /*TextMatch*/ dynamic value, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, + NormalizerFn Function([NormalizerOptions?])? normalizer, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => within(container).findAllByDisplayValue(value, @@ -526,8 +526,8 @@ E getByLabelText( Node container, /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - String selector, + NormalizerFn Function([NormalizerOptions?])? normalizer, + String? selector, }) => within(container).getByLabelText(text, exact: exact, normalizer: normalizer, selector: selector); @@ -558,8 +558,8 @@ List getAllByLabelText( Node container, /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - String selector, + NormalizerFn Function([NormalizerOptions?])? normalizer, + String? selector, }) => within(container).getAllByLabelText(text, exact: exact, normalizer: normalizer, selector: selector); @@ -590,8 +590,8 @@ E queryByLabelText( Node container, /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - String selector, + NormalizerFn Function([NormalizerOptions?])? normalizer, + String? selector, }) => within(container).queryByLabelText(text, exact: exact, normalizer: normalizer, selector: selector); @@ -622,8 +622,8 @@ List queryAllByLabelText( Node container, /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - String selector, + NormalizerFn Function([NormalizerOptions?])? normalizer, + String? selector, }) => within(container).queryAllByLabelText(text, exact: exact, normalizer: normalizer, selector: selector); @@ -664,11 +664,11 @@ Future findByLabelText( Node container, /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - String selector, - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, + NormalizerFn Function([NormalizerOptions?])? normalizer, + String? selector, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => within(container).findByLabelText(text, @@ -717,11 +717,11 @@ Future> findAllByLabelText( Node container, /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - String selector, - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, + NormalizerFn Function([NormalizerOptions?])? normalizer, + String? selector, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => within(container).findAllByLabelText(text, @@ -765,7 +765,7 @@ E getByPlaceholderText( Node container, /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => within(container).getByPlaceholderText(text, exact: exact, normalizer: normalizer); @@ -797,7 +797,7 @@ List getAllByPlaceholderText( Node container, /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => within(container).getAllByPlaceholderText(text, exact: exact, normalizer: normalizer); @@ -829,7 +829,7 @@ E queryByPlaceholderText( Node container, /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => within(container).queryByPlaceholderText(text, exact: exact, normalizer: normalizer); @@ -861,7 +861,7 @@ List queryAllByPlaceholderText( Node container, /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => within(container).queryAllByPlaceholderText(text, exact: exact, normalizer: normalizer); @@ -903,10 +903,10 @@ Future findByPlaceholderText( Node container, /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, + NormalizerFn Function([NormalizerOptions?])? normalizer, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => within(container).findByPlaceholderText(text, @@ -955,10 +955,10 @@ Future> findAllByPlaceholderText( Node container, /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, + NormalizerFn Function([NormalizerOptions?])? normalizer, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => within(container).findAllByPlaceholderText(text, @@ -1006,15 +1006,15 @@ E getByRole( Node container, /*TextMatch*/ dynamic role, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, bool hidden = false, /*TextMatch*/ dynamic name, - bool selected, - bool checked, - bool pressed, - bool expanded, + bool? selected, + bool? checked, + bool? pressed, + bool? expanded, bool queryFallbacks = false, - int level, + int? level, }) => within(container).getByRole(role, exact: exact, @@ -1061,15 +1061,15 @@ List getAllByRole( Node container, /*TextMatch*/ dynamic role, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, bool hidden = false, /*TextMatch*/ dynamic name, - bool selected, - bool checked, - bool pressed, - bool expanded, + bool? selected, + bool? checked, + bool? pressed, + bool? expanded, bool queryFallbacks = false, - int level, + int? level, }) => within(container).getAllByRole(role, exact: exact, @@ -1116,15 +1116,15 @@ E queryByRole( Node container, /*TextMatch*/ dynamic role, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, bool hidden = false, /*TextMatch*/ dynamic name, - bool selected, - bool checked, - bool pressed, - bool expanded, + bool? selected, + bool? checked, + bool? pressed, + bool? expanded, bool queryFallbacks = false, - int level, + int? level, }) => within(container).queryByRole(role, exact: exact, @@ -1172,15 +1172,15 @@ List queryAllByRole( Node container, /*TextMatch*/ dynamic role, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, bool hidden = false, /*TextMatch*/ dynamic name, - bool selected, - bool checked, - bool pressed, - bool expanded, + bool? selected, + bool? checked, + bool? pressed, + bool? expanded, bool queryFallbacks = false, - int level, + int? level, }) => within(container).queryAllByRole(role, exact: exact, @@ -1239,18 +1239,18 @@ Future findByRole( Node container, /*TextMatch*/ dynamic role, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, bool hidden = false, /*TextMatch*/ dynamic name, - bool selected, - bool checked, - bool pressed, - bool expanded, + bool? selected, + bool? checked, + bool? pressed, + bool? expanded, bool queryFallbacks = false, - int level, - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, + int? level, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => within(container).findByRole(role, @@ -1314,18 +1314,18 @@ Future> findAllByRole( Node container, /*TextMatch*/ dynamic role, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, bool hidden = false, /*TextMatch*/ dynamic name, - bool selected, - bool checked, - bool pressed, - bool expanded, + bool? selected, + bool? checked, + bool? pressed, + bool? expanded, bool queryFallbacks = false, - int level, - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, + int? level, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => within(container).findAllByRole(role, @@ -1376,7 +1376,7 @@ E getByTestId( Node container, /*TextMatch*/ dynamic testId, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => within(container).getByTestId(testId, exact: exact, normalizer: normalizer); @@ -1408,7 +1408,7 @@ List getAllByTestId( Node container, /*TextMatch*/ dynamic testId, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => within(container).getAllByTestId(testId, exact: exact, normalizer: normalizer); @@ -1440,7 +1440,7 @@ E queryByTestId( Node container, /*TextMatch*/ dynamic testId, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => within(container).queryByTestId(testId, exact: exact, normalizer: normalizer); @@ -1472,7 +1472,7 @@ List queryAllByTestId( Node container, /*TextMatch*/ dynamic testId, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => within(container).queryAllByTestId(testId, exact: exact, normalizer: normalizer); @@ -1514,10 +1514,10 @@ Future findByTestId( Node container, /*TextMatch*/ dynamic testId, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, + NormalizerFn Function([NormalizerOptions?])? normalizer, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => within(container).findByTestId(testId, @@ -1566,10 +1566,10 @@ Future> findAllByTestId( Node container, /*TextMatch*/ dynamic testId, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, + NormalizerFn Function([NormalizerOptions?])? normalizer, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => within(container).findAllByTestId(testId, @@ -1613,8 +1613,8 @@ E getByText( Node container, /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - String selector, + NormalizerFn Function([NormalizerOptions?])? normalizer, + String? selector, /*String|bool*/ dynamic ignore = 'script', }) => within(container).getByText(text, exact: exact, normalizer: normalizer, selector: selector, ignore: ignore); @@ -1648,8 +1648,8 @@ List getAllByText( Node container, /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - String selector, + NormalizerFn Function([NormalizerOptions?])? normalizer, + String? selector, /*String|bool*/ dynamic ignore = 'script', }) => within(container).getAllByText(text, exact: exact, normalizer: normalizer, selector: selector, ignore: ignore); @@ -1683,8 +1683,8 @@ E queryByText( Node container, /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - String selector, + NormalizerFn Function([NormalizerOptions?])? normalizer, + String? selector, /*String|bool*/ dynamic ignore = 'script', }) => within(container).queryByText(text, exact: exact, normalizer: normalizer, selector: selector, ignore: ignore); @@ -1718,8 +1718,8 @@ List queryAllByText( Node container, /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - String selector, + NormalizerFn Function([NormalizerOptions?])? normalizer, + String? selector, /*String|bool*/ dynamic ignore = 'script', }) => within(container).queryAllByText(text, exact: exact, normalizer: normalizer, selector: selector, ignore: ignore); @@ -1764,12 +1764,12 @@ Future findByText( Node container, /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - String selector, + NormalizerFn Function([NormalizerOptions?])? normalizer, + String? selector, /*String|bool*/ dynamic ignore = 'script', - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => within(container).findByText(text, @@ -1822,12 +1822,12 @@ Future> findAllByText( Node container, /*TextMatch*/ dynamic text, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - String selector, + NormalizerFn Function([NormalizerOptions?])? normalizer, + String? selector, /*String|bool*/ dynamic ignore = 'script', - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => within(container).findAllByText(text, @@ -1872,7 +1872,7 @@ E getByTitle( Node container, /*TextMatch*/ dynamic title, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => within(container).getByTitle(title, exact: exact, normalizer: normalizer); @@ -1904,7 +1904,7 @@ List getAllByTitle( Node container, /*TextMatch*/ dynamic title, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => within(container).getAllByTitle(title, exact: exact, normalizer: normalizer); @@ -1936,7 +1936,7 @@ E queryByTitle( Node container, /*TextMatch*/ dynamic title, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => within(container).queryByTitle(title, exact: exact, normalizer: normalizer); @@ -1968,7 +1968,7 @@ List queryAllByTitle( Node container, /*TextMatch*/ dynamic title, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, }) => within(container).queryAllByTitle(title, exact: exact, normalizer: normalizer); @@ -2010,10 +2010,10 @@ Future findByTitle( Node container, /*TextMatch*/ dynamic title, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, + NormalizerFn Function([NormalizerOptions?])? normalizer, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => within(container).findByTitle(title, @@ -2062,10 +2062,10 @@ Future> findAllByTitle( Node container, /*TextMatch*/ dynamic title, { bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, - Duration timeout, - Duration interval, - QueryTimeoutFn onTimeout, + NormalizerFn Function([NormalizerOptions?])? normalizer, + Duration? timeout, + Duration? interval, + QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => within(container).findAllByTitle(title, diff --git a/lib/src/dom/within.dart b/lib/src/dom/within.dart index 63b8c268..e5bc7e8b 100644 --- a/lib/src/dom/within.dart +++ b/lib/src/dom/within.dart @@ -33,7 +33,7 @@ class WithinQueries extends ScopedQueries { WithinQueries._(this.container) : super(() => container); /// The node within which the queries are scoped. - final Node container; + final Node? container; } /// Takes a DOM [node] and binds it to the raw query functions. @@ -49,12 +49,12 @@ class WithinQueries extends ScopedQueries { /// > See: /// /// {@category Queries} -WithinQueries within(Node node) { +WithinQueries within(Node? node) { if (node == null) { throw ArgumentError.notNull('node'); } - if (node is! ShadowRoot && !isOrContains(document.body, node)) { + if (node is! ShadowRoot && !isOrContains(document.body!, node)) { throw ArgumentError.value( node, 'node', @@ -73,9 +73,9 @@ class ScreenQueries extends WithinQueries { /// /// > See: void debug([ - Node baseElement, - int maxLength, - PrettyDomOptions options, + Node? baseElement, + int? maxLength, + PrettyDomOptions? options, ]) => printConsoleLogs(() => _screen.debug(baseElement, maxLength, options)); } diff --git a/lib/src/matchers/jest_dom/css_class_matchers.dart b/lib/src/matchers/jest_dom/css_class_matchers.dart index 6ebb86b1..e81a375e 100644 --- a/lib/src/matchers/jest_dom/css_class_matchers.dart +++ b/lib/src/matchers/jest_dom/css_class_matchers.dart @@ -16,6 +16,7 @@ import 'dart:html'; import 'dart:svg' show AnimatedString; +import 'package:collection/collection.dart' show IterableNullableExtension; import 'package:matcher/matcher.dart'; import 'package:react_testing_library/src/matchers/jest_dom/util/constants.dart'; @@ -170,7 +171,7 @@ class _ClassNameMatcher extends Matcher { static Iterable getClassIterable(dynamic classNames) { Iterable classes; if (classNames is Iterable) { - classes = classNames.where((className) => className != null).expand(_splitSpaceDelimitedString); + classes = classNames.whereNotNull().expand(_splitSpaceDelimitedString); } else if (classNames is String) { classes = _splitSpaceDelimitedString(classNames); } else { @@ -185,7 +186,7 @@ class _ClassNameMatcher extends Matcher { // There's a bug in DDC where, though the docs say `className` should // return `String`, it will return `AnimatedString` for `SvgElement`s. See // https://github.com/dart-lang/sdk/issues/36200. - String castClassName; + String? castClassName; if (className is String) { castClassName = className; } else if (className is AnimatedString) { @@ -233,16 +234,16 @@ class _ClassNameMatcher extends Matcher { @override Description describeMismatch(dynamic item, Description mismatchDescription, Map matchState, bool verbose) { final missingClasses = matchState['missingClasses'] as Set; - final unwantedClasses = matchState['unwantedClasses'] as Set; - final extraneousClasses = matchState['extraneousClasses'] as List; + final unwantedClasses = matchState['unwantedClasses'] as Set?; + final extraneousClasses = matchState['extraneousClasses'] as List?; final descriptionParts = []; if (allowExtraneous) { - if (unwantedClasses.isNotEmpty) { + if (unwantedClasses!.isNotEmpty) { descriptionParts.add('has unwanted classes: $unwantedClasses'); } } else { - if (extraneousClasses.isNotEmpty) { + if (extraneousClasses!.isNotEmpty) { descriptionParts.add('has extraneous classes: $extraneousClasses'); } } diff --git a/lib/src/matchers/jest_dom/has_attribute.dart b/lib/src/matchers/jest_dom/has_attribute.dart index 9cac136c..3ef8f102 100644 --- a/lib/src/matchers/jest_dom/has_attribute.dart +++ b/lib/src/matchers/jest_dom/has_attribute.dart @@ -84,7 +84,7 @@ class _ElementAttributeMatcher extends CustomMatcher { Description describeMismatch(dynamic item, Description mismatchDescription, Map matchState, bool verbose) { if (item is! Element) { return mismatchDescription..add(notAnElementMismatchDescription); - } else if (_valueOrMatcher != null && (item as Element).getAttribute(_attributeName) == null) { + } else if (_valueOrMatcher != null && item.getAttribute(_attributeName) == null) { return mismatchDescription..add('does not have an "$_attributeName" attribute.'); } diff --git a/lib/src/matchers/jest_dom/has_description.dart b/lib/src/matchers/jest_dom/has_description.dart index e8db8274..aafe9bca 100644 --- a/lib/src/matchers/jest_dom/has_description.dart +++ b/lib/src/matchers/jest_dom/has_description.dart @@ -122,17 +122,17 @@ class _HasDescription extends CustomMatcher with ElementTextContentMatcherMixin } else if (_elementsThatDescribe(item).isEmpty) { return mismatchDescription ..add('has an aria-described by attribute value ' - 'of "${(item as Element).getAttribute('aria-describedby')}", which does not match the id attribute of ' + 'of "${item.getAttribute('aria-describedby')}", which does not match the id attribute of ' 'any Element in the DOM.'); } return super.describeMismatch(item, mismatchDescription, matchState, verbose); } - List _idsOfElementsThatDescribe(item) { + List? _idsOfElementsThatDescribe(item) { if (item is! Element) return null; - final describedByAttrValue = (item as Element).getAttribute('aria-describedby'); + final describedByAttrValue = item.getAttribute('aria-describedby'); if (describedByAttrValue == null) return null; return describedByAttrValue.split(' '); } diff --git a/lib/src/matchers/jest_dom/has_form_values.dart b/lib/src/matchers/jest_dom/has_form_values.dart index 9edd5bc8..6c26709e 100644 --- a/lib/src/matchers/jest_dom/has_form_values.dart +++ b/lib/src/matchers/jest_dom/has_form_values.dart @@ -16,6 +16,7 @@ import 'dart:html'; import 'dart:js'; +import 'package:collection/collection.dart' show IterableExtension; import 'package:matcher/matcher.dart'; import 'package:react_testing_library/dom/debugging.dart'; import 'package:react_testing_library/src/matchers/jest_dom/util/constants.dart'; @@ -98,7 +99,7 @@ class _HasFormValues extends CustomMatcher { // If it's not a FormElement, the mismatch description will say so. if (item is! Element) return null; - final element = item as Element; + final element = item; final actualNamesAndValues = {}; valuesMap.forEach((elementNameToTest, value) { @@ -122,17 +123,16 @@ class _HasFormValues extends CustomMatcher { actualNamesAndValues[elementNameToTest] = childElement.checked; } else { final selectedCheckboxElements = - allCheckboxesWithName.where((cboxEl) => (cboxEl as CheckboxInputElement).checked); + allCheckboxesWithName.where((cboxEl) => (cboxEl as CheckboxInputElement).checked!); actualNamesAndValues[elementNameToTest] = selectedCheckboxElements.map((el) => el.getAttribute('value')).toList(); } break; case 'radio': final allRadiosWithName = element.querySelectorAll('input[type="radio"][name="$childElementName"]'); - final selectedRadioElement = allRadiosWithName.singleWhere( - (radioEl) => (radioEl as RadioButtonInputElement).checked, - orElse: () => null, - ) as RadioButtonInputElement; + final selectedRadioElement = allRadiosWithName.singleWhereOrNull( + (radioEl) => (radioEl as RadioButtonInputElement).checked!, + ) as RadioButtonInputElement?; actualNamesAndValues[elementNameToTest] = selectedRadioElement?.value; break; default: @@ -156,14 +156,14 @@ class _HasFormValues extends CustomMatcher { var extraDescription = ''; - if (getItemFormElementsToTest(item as Element).isEmpty) { + if (getItemFormElementsToTest(item).isEmpty) { extraDescription = '\n\nNo elements were found with names matching ${valuesMap.keys}.'; } return super.describeMismatch(item, mismatchDescription, matchState, verbose).add(extraDescription).add( // ignore: prefer_interpolation_to_compose_strings '\n\nThe DOM at time of failure is shown below:\n------------------------------------------\n' + - prettyDOM(item as Element)); + prettyDOM(item)); } } @@ -177,5 +177,5 @@ JsObject _getJsFormOrFieldSet(Element form) => JsObject.fromBrowserObject(form); /// Wraps the [HTMLFormElement.elements](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/elements) property. List getFormElements(Element form) { assert(form is FormElement || form is FieldSetElement); - return convertToArray(_getJsFormOrFieldSet(form)['elements'] as JsObject); + return convertToArray(_getJsFormOrFieldSet(form)['elements'] as JsObject?); } diff --git a/lib/src/matchers/jest_dom/has_styles.dart b/lib/src/matchers/jest_dom/has_styles.dart index 7dea34c7..6fab1483 100644 --- a/lib/src/matchers/jest_dom/has_styles.dart +++ b/lib/src/matchers/jest_dom/has_styles.dart @@ -86,7 +86,7 @@ class _HasStyles extends CustomMatcher { // If it's not a Element, the mismatch description will say so. if (item is! Element) return null; - final element = item as Element; + final element = item; final allComputedStyles = element.getComputedStyle(); final stylesToCompare = {}; @@ -130,11 +130,11 @@ class _HasStyles extends CustomMatcher { normalizedValue = normalizedValue.toString().replaceAllMapped(RegExp(r',(\S)'), (match) { return ', ${match.group(1)}'; }).replaceAllMapped(RegExp(r'(?<=\D)0(\.\d)'), (match) { - return match.group(1); + return match.group(1)!; }); if (normalizedValue is String) { - normalizedValue = num.tryParse(normalizedValue as String) ?? normalizedValue; + normalizedValue = num.tryParse(normalizedValue) as String? ?? normalizedValue; } return normalizedValue; @@ -146,7 +146,7 @@ class _HasStyles extends CustomMatcher { final valueAsColor = ColorParser().parse(possibleColorValue.toString()); if (valueAsColor != null) { if (RgbColor.namedColors.containsKey(possibleColorValue)) { - return RgbColor.namedColors[possibleColorValue].toCssString(); + return RgbColor.namedColors[possibleColorValue]!.toCssString(); } final rgbColor = valueAsColor.toRgbColor(); @@ -158,5 +158,5 @@ class _HasStyles extends CustomMatcher { } String _camelToDashCase(String camel) { - return camel.replaceAllMapped(RegExp(r'[A-Z]'), (match) => '-${match[0].toLowerCase()}'); + return camel.replaceAllMapped(RegExp(r'[A-Z]'), (match) => '-${match[0]!.toLowerCase()}'); } diff --git a/lib/src/matchers/jest_dom/has_value.dart b/lib/src/matchers/jest_dom/has_value.dart index 41a9bd20..d13cb61c 100644 --- a/lib/src/matchers/jest_dom/has_value.dart +++ b/lib/src/matchers/jest_dom/has_value.dart @@ -100,7 +100,7 @@ Matcher hasDisplayValue([dynamic value]) => class _HasValue extends CustomMatcher { final dynamic expectedValue; - final dynamic Function(OptionElement option) getOptionValue; + final dynamic Function(OptionElement option)? getOptionValue; _HasValue(this.expectedValue, {this.getOptionValue, String valueDescription = 'value'}) : super('An element with ${expectedValue == null ? 'no $valueDescription' : 'a $valueDescription of'}', 'element', @@ -119,7 +119,7 @@ class _HasValue extends CustomMatcher { // If it's not a Element, the mismatch description will say so. if (item is! Element) return null; - final element = item as Element; + final element = item; if (element is InputElement) { final type = element.getAttribute('type'); diff --git a/lib/src/matchers/jest_dom/is_checked.dart b/lib/src/matchers/jest_dom/is_checked.dart index 6dea5637..ff85e564 100644 --- a/lib/src/matchers/jest_dom/is_checked.dart +++ b/lib/src/matchers/jest_dom/is_checked.dart @@ -94,11 +94,11 @@ class _IsChecked extends Matcher { bool isElementThatCanBeChecked(dynamic item, Map matchState) => item != null && matchState['isElement'] as bool && matchState['canBeChecked'] as bool; - bool/*!*/ isElementChecked(Element item, Map matchState) { + bool isElementChecked(Element item, Map matchState) { if (item is InputElement) { final type = item.getAttribute('type'); if (_validTypes.contains(type)) { - return item.checked; + return item.checked!; } } @@ -125,7 +125,7 @@ class _IsChecked extends Matcher { if (!isElementThatCanBeChecked(item, matchState)) return false; - return isElementChecked(item as Element/*!*/, matchState); + return isElementChecked(item as Element, matchState); } @override diff --git a/lib/src/matchers/jest_dom/is_disabled.dart b/lib/src/matchers/jest_dom/is_disabled.dart index cadafd5b..b23ac32b 100644 --- a/lib/src/matchers/jest_dom/is_disabled.dart +++ b/lib/src/matchers/jest_dom/is_disabled.dart @@ -85,7 +85,7 @@ class _IsDisabled extends Matcher { bool isElementThatCanBeDisabled(dynamic item, Map matchState) => item != null && matchState['isElement'] as bool && matchState['canBeDisabled'] as bool; - bool/*!*/ isElementDisabled(dynamic item, Map matchState) { + bool isElementDisabled(dynamic item, Map matchState) { if (!isElementThatCanBeDisabled(item, matchState)) return false; final formAncestor = (item as Element).closest('form'); if (formAncestor != null && (formAncestor as FormElement).hasAttribute('disabled')) return true; diff --git a/lib/src/matchers/jest_dom/is_empty_dom_element.dart b/lib/src/matchers/jest_dom/is_empty_dom_element.dart index 4c9f6c27..35007832 100644 --- a/lib/src/matchers/jest_dom/is_empty_dom_element.dart +++ b/lib/src/matchers/jest_dom/is_empty_dom_element.dart @@ -68,7 +68,7 @@ class _IsEmptyDomElement extends Matcher { matchState['isElement'] = item is Element; if (item == null || item is! Element) return false; - return (item as Element).innerHtml.isEmpty; + return item.innerHtml!.isEmpty; } @override diff --git a/lib/src/matchers/jest_dom/is_focused.dart b/lib/src/matchers/jest_dom/is_focused.dart index dff9abc7..963ff9f4 100644 --- a/lib/src/matchers/jest_dom/is_focused.dart +++ b/lib/src/matchers/jest_dom/is_focused.dart @@ -78,7 +78,7 @@ class _IsFocused extends Matcher { return mismatchDescription..add(notAnElementMismatchDescription); } - if (!document.documentElement.contains(item as Element)) { + if (!document.documentElement!.contains(item)) { return mismatchDescription ..add('is not attached to the document, and thus cannot be focused.') ..add(' If testing with React, you should use the `render` utility function ' diff --git a/lib/src/matchers/jest_dom/is_in_the_document.dart b/lib/src/matchers/jest_dom/is_in_the_document.dart index 0b1ca197..d8ff2adb 100644 --- a/lib/src/matchers/jest_dom/is_in_the_document.dart +++ b/lib/src/matchers/jest_dom/is_in_the_document.dart @@ -77,7 +77,7 @@ class _IsInTheDocument extends Matcher { @override bool matches(dynamic item, Map matchState) { if (item is! Element) return false; - return item != null && (item as Element).ownerDocument == (item as Element).getRootNode({'composed': true}); + return item != null && item.ownerDocument == item.getRootNode({'composed': true}); } @override diff --git a/lib/src/matchers/jest_dom/is_partially_checked.dart b/lib/src/matchers/jest_dom/is_partially_checked.dart index dc41426e..e35313d7 100644 --- a/lib/src/matchers/jest_dom/is_partially_checked.dart +++ b/lib/src/matchers/jest_dom/is_partially_checked.dart @@ -98,19 +98,19 @@ class _IsPartiallyChecked extends Matcher { bool isElementThatCanBePartiallyChecked(dynamic item, Map matchState) => item != null && matchState['isElement'] as bool && matchState['canBePartiallyChecked'] as bool; - bool/*!*/ isElementPartiallyChecked(dynamic item, Map matchState) { + bool isElementPartiallyChecked(dynamic item, Map matchState) { if (item is! Element) return false; if (item is InputElement) { final type = item.getAttribute('type'); if (type == 'checkbox') { - return item.indeterminate; + return item.indeterminate!; } } - final role = (item as Element).getAttribute('role'); + final role = item.getAttribute('role'); if (role == 'checkbox') { - final ariaPartiallyCheckedValue = (item as Element).getAttribute('aria-checked'); + final ariaPartiallyCheckedValue = item.getAttribute('aria-checked'); return ariaPartiallyCheckedValue == 'mixed'; } diff --git a/lib/src/matchers/jest_dom/util/element_text_content_matcher_mixin.dart b/lib/src/matchers/jest_dom/util/element_text_content_matcher_mixin.dart index 97215918..af4fd0a7 100644 --- a/lib/src/matchers/jest_dom/util/element_text_content_matcher_mixin.dart +++ b/lib/src/matchers/jest_dom/util/element_text_content_matcher_mixin.dart @@ -19,11 +19,11 @@ import 'package:matcher/matcher.dart'; /// A mixin with utilities for matchers that match [Element] text content. mixin ElementTextContentMatcherMixin on CustomMatcher { - static String getNormalizedTextContentOf(dynamic item, {bool normalizeWhitespace = true}) { + static String? getNormalizedTextContentOf(dynamic item, {bool normalizeWhitespace = true}) { if (item is! Element) return null; - if (!normalizeWhitespace) return (item as Element).text; + if (!normalizeWhitespace) return item.text; - return (item as Element).text.replaceAll(RegExp(r'\s+'), ' '); + return item.text!.replaceAll(RegExp(r'\s+'), ' '); } /// Returns a normalized [String] or [Matcher] based on the provided [userExpectedTextContent] diff --git a/lib/src/matchers/jest_dom/util/get_value_of.dart b/lib/src/matchers/jest_dom/util/get_value_of.dart index ca34159b..dcd0e9eb 100644 --- a/lib/src/matchers/jest_dom/util/get_value_of.dart +++ b/lib/src/matchers/jest_dom/util/get_value_of.dart @@ -22,7 +22,7 @@ import 'dart:html'; /// /// This function does not support `` or `` value parsing. /// The `hasFormValues` matcher has special logic built-in for that. -dynamic getValueOf(Element element, {dynamic Function(OptionElement option) getOptionValue}) { +dynamic getValueOf(Element element, {dynamic Function(OptionElement option)? getOptionValue}) { if (element is InputElement) { final type = element.getAttribute('type'); switch (type) { @@ -30,7 +30,7 @@ dynamic getValueOf(Element element, {dynamic Function(OptionElement option) getO case 'radio': throw ArgumentError('getValueOf() does not support checkbox / radio inputs.'); case 'number': - return num.tryParse(element.value) ?? element.value; + return num.tryParse(element.value!) ?? element.value; case 'text': default: return element.value; @@ -39,10 +39,10 @@ dynamic getValueOf(Element element, {dynamic Function(OptionElement option) getO getOptionValue ??= (option) => option.value; final selectedOptions = element.options.where((option) => option.selected); if (selectedOptions.isEmpty) { - return element.multiple ? const [] : null; + return element.multiple! ? const [] : null; } else if (selectedOptions.length == 1) { final selectedValues = selectedOptions.map(getOptionValue); - return element.multiple ? selectedValues.toList() : selectedValues.single; + return element.multiple! ? selectedValues.toList() : selectedValues.single; } else { return selectedOptions.map(getOptionValue).toList(); } diff --git a/lib/src/react/render/render.dart b/lib/src/react/render/render.dart index 6049ca62..57ef0bc3 100644 --- a/lib/src/react/render/render.dart +++ b/lib/src/react/render/render.dart @@ -106,15 +106,15 @@ import 'package:react_testing_library/src/react/render/types.dart' show JsRender /// At this time, the Dart API does not support them. If you have a use case for custom queries - /// [we would love to hear more about it!](https://github.com/Workiva/react_testing_library/issues/new) RenderResult render( - ReactElement/*!*/ ui, { - Node container, - Node baseElement, + ReactElement ui, { + Node? container, + Node? baseElement, bool hydrate = false, // TODO: Implement if CPLAT-13502 is deemed necessary // Map queries, /*UiFactory || ReactComponentFactoryProxy*/ dynamic wrapper, bool autoTearDown = true, - void Function() onDidTearDown, + void Function()? onDidTearDown, }) { // ignore: invalid_use_of_visible_for_testing_member componentZone = Zone.current; @@ -193,16 +193,16 @@ class RenderResult extends ScopedQueries { /// /// > See: void debug([ - Node baseElement, - int maxLength, - PrettyDomOptions options, + Node? baseElement, + int? maxLength, + PrettyDomOptions? options, ]) => printConsoleLogs(() => _jsRenderResult.debug(baseElement, maxLength, options)); /// Updates the props of the [renderedElement] by providing an updated [ui] element. /// /// > See: - void rerender(ReactElement/*!*/ ui) { + void rerender(ReactElement ui) { _renderedElement = ui; _jsRenderResult.rerender(ui); } diff --git a/lib/src/react/render/types.dart b/lib/src/react/render/types.dart index 345d4e67..052fedef 100644 --- a/lib/src/react/render/types.dart +++ b/lib/src/react/render/types.dart @@ -35,9 +35,9 @@ class JsRenderResult { external Node get baseElement; external void debug([ - Node baseElement, - int maxLength, - PrettyDomOptions options, + Node? baseElement, + int? maxLength, + PrettyDomOptions? options, ]); external void rerender(ReactElement ui); diff --git a/lib/src/user_event/user_event.dart b/lib/src/user_event/user_event.dart index 5d86e9f0..7c08ee1b 100644 --- a/lib/src/user_event/user_event.dart +++ b/lib/src/user_event/user_event.dart @@ -112,7 +112,7 @@ abstract class UserEvent { /// {@category UserActions} static void click( Element element, { - Map eventInit, + Map? eventInit, bool skipHover = false, int clickCount = 0, bool skipPointerEventsCheck = false, @@ -201,7 +201,7 @@ abstract class UserEvent { /// {@macro RenderSupportsReactAndOverReactCallout} /// /// {@category UserActions} - static void dblClick(Element element, {Map eventInit, bool skipPointerEventsCheck = false}) { + static void dblClick(Element element, {Map? eventInit, bool skipPointerEventsCheck = false}) { final options = { 'skipPointerEventsCheck': skipPointerEventsCheck, }; @@ -304,13 +304,13 @@ abstract class UserEvent { /// /// {@category UserActions} static void type( - Element/*!*/ element, + Element element, String text, { bool skipClick = false, bool skipAutoClose = false, // The follow two options currently do not work as expected. - int initialSelectionStart, - int initialSelectionEnd, + int? initialSelectionStart, + int? initialSelectionEnd, }) { final options = { 'skipClick': skipClick, @@ -420,7 +420,7 @@ abstract class UserEvent { /// /// {@category UserActions} static Future typeWithDelay( - Element/*!*/ element, + Element element, String text, Duration delay, { bool skipClick = false, @@ -521,9 +521,9 @@ abstract class UserEvent { /// {@category UserActions} static KeyboardState keyboard( String text, { - KeyboardState keyboardState, + KeyboardState? keyboardState, bool autoModify = false, - List keyboardMap, + List? keyboardMap, }) { final options = { 'autoModify': autoModify, @@ -534,7 +534,7 @@ abstract class UserEvent { return getProperty(_userEvent, 'keyboard')( text, jsifyAndAllowInterop(options), - ) as KeyboardState/*!*/; + ) as KeyboardState; }); } @@ -618,9 +618,9 @@ abstract class UserEvent { static Future keyboardWithDelay( String text, Duration delay, { - KeyboardState keyboardState, + KeyboardState? keyboardState, bool autoModify = false, - List keyboardMap, + List? keyboardMap, }) { final options = { 'delay': delay.inMilliseconds, @@ -750,8 +750,8 @@ abstract class UserEvent { static void upload( /*InputElement | LabelElement*/ Element element, List files, { - Map clickInit, - Map changeInit, + Map? clickInit, + Map? changeInit, bool applyAccept = false, }) { final init = { @@ -912,7 +912,7 @@ abstract class UserEvent { static void selectOptions( SelectElement selectElement, List values, { - Map clickInit, + Map? clickInit, bool skipPointerEventsCheck = false, }) { final options = { @@ -1015,7 +1015,7 @@ abstract class UserEvent { static void deselectOptions( SelectElement selectElement, List values, { - Map clickInit, + Map? clickInit, bool skipPointerEventsCheck = false, }) { final options = { @@ -1123,7 +1123,7 @@ abstract class UserEvent { /// {@macro RenderSupportsReactAndOverReactCallout} /// /// {@category UserActions} - static void tab({bool shift = false, Element focusTrap}) { + static void tab({bool shift = false, Element? focusTrap}) { final options = {'shift': shift, 'focusTrap': focusTrap}; eventHandlerErrorCatcher(() { getProperty(_userEvent, 'tab')( @@ -1211,7 +1211,7 @@ abstract class UserEvent { /// {@category UserActions} static void hover( Element element, { - Map eventInit, + Map? eventInit, bool skipPointerEventsCheck = false, }) { final options = { @@ -1310,7 +1310,7 @@ abstract class UserEvent { /// {@macro RenderSupportsReactAndOverReactCallout} /// /// {@category UserActions} - static void unhover(Element element, {Map eventInit, bool skipPointerEventsCheck = false}) { + static void unhover(Element element, {Map? eventInit, bool skipPointerEventsCheck = false}) { final options = { 'skipPointerEventsCheck': skipPointerEventsCheck, }; @@ -1389,11 +1389,11 @@ abstract class UserEvent { /// /// {@category UserActions} static void paste( - Element/*!*/ element, + Element element, String text, { - Map eventInit, - int initialSelectionStart, - int initialSelectionEnd, + Map? eventInit, + int? initialSelectionStart, + int? initialSelectionEnd, }) { final options = { if (initialSelectionStart != null) 'initialSelectionStart': initialSelectionStart, @@ -1421,10 +1421,10 @@ class KeyboardState { external factory KeyboardState._(); } -dynamic _jsifyEventData(Map eventData) => jsifyAndAllowInterop(eventData ?? const {}); +dynamic _jsifyEventData(Map? eventData) => jsifyAndAllowInterop(eventData ?? const {}); // Converts a JsMap FileList to a List. -List _unjsifyFileList(List fileList) { +List _unjsifyFileList(List? fileList) { if (fileList is FileList) return fileList; final jsFileList = JsBackedMap.fromJs((fileList ?? []) as JsMap); diff --git a/lib/src/util/console_log_formatter.dart b/lib/src/util/console_log_formatter.dart index 56fe4105..8780b196 100644 --- a/lib/src/util/console_log_formatter.dart +++ b/lib/src/util/console_log_formatter.dart @@ -54,7 +54,7 @@ String format(dynamic f, List arguments) { str += f.replaceAllMapped(_formatRegExp, (m) { final x = m[0]; if (x == '%%') return '%'; - if (i >= len) return x; + if (i >= len) return x!; switch (x) { case '%s': return arguments[i++].toString(); @@ -73,7 +73,7 @@ String format(dynamic f, List arguments) { } break; default: - return x; + return x!; } }); diff --git a/lib/src/util/console_log_utils.dart b/lib/src/util/console_log_utils.dart index bc97a90d..6a85353d 100644 --- a/lib/src/util/console_log_utils.dart +++ b/lib/src/util/console_log_utils.dart @@ -68,7 +68,7 @@ T printConsoleLogs( /// See also: [printConsoleLogs], [startSpyingOnConsoleLogs] T spyOnConsoleLogs( T Function() callback, { - @required void Function(String) onLog, + required void Function(String) onLog, ConsoleConfig configuration = ConsoleConfig.all, }) { final stopSpying = startSpyingOnConsoleLogs(configuration: configuration, onLog: onLog); @@ -93,7 +93,7 @@ T spyOnConsoleLogs( /// See also: [printConsoleLogs], [spyOnConsoleLogs] void Function() startSpyingOnConsoleLogs({ ConsoleConfig configuration = ConsoleConfig.all, - @required void Function(String) onLog, + required void Function(String) onLog, }) { final logTypeToCapture = configuration.logType == 'all' ? ConsoleConfig.types : [configuration.logType]; final consoleRefs = {}; diff --git a/lib/src/util/error_message_utils.dart b/lib/src/util/error_message_utils.dart index 9e0975f6..72284b99 100644 --- a/lib/src/util/error_message_utils.dart +++ b/lib/src/util/error_message_utils.dart @@ -26,7 +26,7 @@ import 'package:react_testing_library/src/dom/config/configure.dart' show config /// if any queries fail in the current test. void setEphemeralElementErrorMessage( Object Function(Object originalMessage, Element container) customErrorMessageBuilder, - {StackTrace jsStackTrace}) { + {StackTrace? jsStackTrace}) { TestingLibraryElementError buildCustomDartGetElementError(Object originalMessage, Element container) { return TestingLibraryElementError.fromJs( buildJsGetElementError(customErrorMessageBuilder(originalMessage, container), container), jsStackTrace); @@ -53,13 +53,13 @@ T withErrorInterop(T Function() getJsQueryResult) { class TestingLibraryElementError extends Error { TestingLibraryElementError(this.message, [this.jsStackTrace]) : super(); - factory TestingLibraryElementError.fromJs(/*JsError*/ dynamic jsError, [StackTrace jsStackTrace]) { + factory TestingLibraryElementError.fromJs(/*JsError*/ dynamic jsError, [StackTrace? jsStackTrace]) { final stack = jsError is JsError ? jsStackTrace ?? StackTrace.fromString(jsError.stack) : null; return TestingLibraryElementError(jsError.toString(), stack); } final String message; - final StackTrace jsStackTrace; + final StackTrace? jsStackTrace; @override String toString() => '$message\n\n' diff --git a/lib/src/util/is_or_contains.dart b/lib/src/util/is_or_contains.dart index 3ea8f398..bda1e669 100644 --- a/lib/src/util/is_or_contains.dart +++ b/lib/src/util/is_or_contains.dart @@ -18,4 +18,4 @@ import 'dart:html' show Node; /// Returns whether [root] is the same as or contains the [other] node. /// /// Returns false if either [root] or [other] is null. -bool isOrContains(Node/*!*/ root, Node other) => (root != null && other != null) && (root == other || root.contains(other)); +bool isOrContains(Node root, Node other) => (root != null && other != null) && (root == other || root.contains(other)); diff --git a/lib/src/util/js_utils.dart b/lib/src/util/js_utils.dart index 01349683..46e1828c 100644 --- a/lib/src/util/js_utils.dart +++ b/lib/src/util/js_utils.dart @@ -17,14 +17,14 @@ import 'dart:js'; /// [Global JavaScript Array Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) // ignore: type_annotate_public_apis -final jsArray = context['Array'] as JsObject/*!*/; +final jsArray = context['Array'] as JsObject; /// Store a helper reference to the global [jsArray]'s [`slice` method](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice) // ignore: type_annotate_public_apis -final arrayProtoSlice = jsArray['prototype']['slice'] as JsObject/*!*/; +final arrayProtoSlice = jsArray['prototype']['slice'] as JsObject; /// Converts the Array-like [object] to a [JsArray] using [arrayProtoSlice]. -JsArray convertToArray(JsObject object) { +JsArray convertToArray(JsObject? object) { final rawArray = (arrayProtoSlice.callMethod('apply', [object]) as Iterable).cast(); return JsArray.from(rawArray); } diff --git a/pubspec.yaml b/pubspec.yaml index 5c2d5fd9..1e7bfa1e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,9 +4,10 @@ description: A Dart unit testing library for OverReact components that mimics th homepage: https://github.com/Workiva/react_testing_library/ documentation: https://workiva.github.io/react_testing_library environment: - sdk: ">=2.11.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' dependencies: + collection: ^1.15.0-nullsafety.4 color: ^3.0.0 js: ^0.6.2 matcher: ^0.12.9 diff --git a/test/unit/console_log_utils_test.dart b/test/unit/console_log_utils_test.dart index cb4927ff..e96e8e59 100644 --- a/test/unit/console_log_utils_test.dart +++ b/test/unit/console_log_utils_test.dart @@ -524,11 +524,11 @@ class _SampleComponent extends react.Component2 { return ArgumentError('${info.propName} is necessary.'); } - if ((props as Map)['shouldLog'] == false && (props as Map)['shouldAlwaysBeFalse'] == false) { + if (props['shouldLog'] == false && props['shouldAlwaysBeFalse'] == false) { return ArgumentError('logging is required.'); } - if ((props as Map)['shouldNeverBeNull'] == false) { + if (props['shouldNeverBeNull'] == false) { return ArgumentError('${info.propName} should not be false.'); } diff --git a/test/unit/dom/accessibility_helpers_test.dart b/test/unit/dom/accessibility_helpers_test.dart index 99810b38..8e3077bb 100644 --- a/test/unit/dom/accessibility_helpers_test.dart +++ b/test/unit/dom/accessibility_helpers_test.dart @@ -80,7 +80,7 @@ void main() { }); group('with hidden elements', () { - rtl.RenderResult view; + late rtl.RenderResult view; setUp(() { view = rtl.render(react.div({}, [ @@ -130,7 +130,7 @@ void main() { }); group('isInaccessible', () { - rtl.RenderResult view; + late rtl.RenderResult view; setUp(() { view = rtl.render(react.div({}, [ @@ -187,12 +187,12 @@ void main() { }); group('getRoles', () { - Map _getLoggedRoleMatches(Node dom, {bool hidden = false}) { + Map _getLoggedRoleMatches(Node? dom, {bool hidden = false}) { final rolePattern = RegExp(r'(\w*):\n\n((.|(\n(?!-)))*)\n\n---'); final printCalls = recordPrintCalls(() => rtl.logRoles(dom, hidden: hidden)); expect(printCalls, hasLength(1)); return { - for (final match in rolePattern.allMatches(printCalls[0])) match[1]: match[2], + for (final match in rolePattern.allMatches(printCalls[0])) match[1]!: match[2]!, }; } @@ -270,7 +270,7 @@ void main() { }); group('with hidden elements', () { - rtl.RenderResult view; + late rtl.RenderResult view; setUp(() { view = rtl.render(react.div({}, [ diff --git a/test/unit/dom/fire_event_test.dart b/test/unit/dom/fire_event_test.dart index 68d4508f..5770869e 100644 --- a/test/unit/dom/fire_event_test.dart +++ b/test/unit/dom/fire_event_test.dart @@ -25,15 +25,15 @@ import '../util/matchers.dart'; void main() { group('', () { - List calls; - rtl.RenderResult view; + late List calls; + late rtl.RenderResult view; setUp(() { calls = []; final elementToRender = react.button({ 'id': 'root', 'onClick': (event) { - calls.add((event as react.SyntheticMouseEvent).nativeEvent as Event/*!*/); + calls.add((event as react.SyntheticMouseEvent).nativeEvent as Event); } }, 'oh hai') as ReactElement; view = rtl.render(elementToRender); diff --git a/test/unit/dom/matchers/css_class_matchers_test.dart b/test/unit/dom/matchers/css_class_matchers_test.dart index 9d343664..05d2775d 100644 --- a/test/unit/dom/matchers/css_class_matchers_test.dart +++ b/test/unit/dom/matchers/css_class_matchers_test.dart @@ -23,7 +23,7 @@ import '../../util/matchers.dart'; void main() { group('', () { - Element testElement; + late Element testElement; setUp(() { testElement = Element.div(); diff --git a/test/unit/dom/matchers/has_attribute_test.dart b/test/unit/dom/matchers/has_attribute_test.dart index 10b8d274..f5acaf66 100644 --- a/test/unit/dom/matchers/has_attribute_test.dart +++ b/test/unit/dom/matchers/has_attribute_test.dart @@ -23,7 +23,7 @@ import '../../util/matchers.dart'; void main() { group('hasAttribute matcher', () { - DivElement testElement; + late DivElement testElement; setUp(() { testElement = DivElement(); diff --git a/test/unit/dom/matchers/has_description_test.dart b/test/unit/dom/matchers/has_description_test.dart index de3b67b9..4182b002 100644 --- a/test/unit/dom/matchers/has_description_test.dart +++ b/test/unit/dom/matchers/has_description_test.dart @@ -26,7 +26,7 @@ import '../../util/matchers.dart'; void main() { group('hasDescription matcher', () { - RenderResult view; + late RenderResult view; setUp(() { view = render(react.div( @@ -47,7 +47,7 @@ void main() { }); group('[element with a single id as its aria-describedby attribute value]', () { - Element closeButtonElement; + late Element closeButtonElement; setUp(() { closeButtonElement = view.getByRole('button', name: 'Close'); }); @@ -76,7 +76,7 @@ void main() { }); group('[element with multiple, space-separated ids as its aria-describedby attribute value]', () { - Element buttonElementWithMultipleDescriptions; + late Element buttonElementWithMultipleDescriptions; setUp(() { buttonElementWithMultipleDescriptions = view.getByRole('button', name: 'Has Multiple Descriptions'); }); diff --git a/test/unit/dom/matchers/has_form_values_test.dart b/test/unit/dom/matchers/has_form_values_test.dart index 85a10c26..59c348a9 100644 --- a/test/unit/dom/matchers/has_form_values_test.dart +++ b/test/unit/dom/matchers/has_form_values_test.dart @@ -56,7 +56,7 @@ void main() { return render(vDom); } - RenderResult view; + late RenderResult view; group('passes when provided with a valid name/value combination for a', () { final unTestedChildFormElemThatShouldNotCauseFailure = _FormElemDefinition(react.input, { @@ -472,7 +472,7 @@ void main() { }); group('provided with a valid name/value combination for a', () { - Matcher getMatcherForExpectedCustomMatcherMessage({@required Map expected, @required Map actual}) { + Matcher getMatcherForExpectedCustomMatcherMessage({required Map expected, required Map actual}) { final expectedFormValuesAsMatcherToStringValue = json .encode(expected) .replaceAll(',', ', ') diff --git a/test/unit/dom/matchers/has_styles_test.dart b/test/unit/dom/matchers/has_styles_test.dart index f6c4635f..c61a1a32 100644 --- a/test/unit/dom/matchers/has_styles_test.dart +++ b/test/unit/dom/matchers/has_styles_test.dart @@ -26,8 +26,8 @@ import '../../util/matchers.dart'; void main() { group('hasStyles matcher', () { - RenderResult view; - StyleElement externalStyleSheet; + late RenderResult view; + late StyleElement externalStyleSheet; tearDown(() { externalStyleSheet?.remove(); @@ -43,7 +43,7 @@ void main() { content: attr(title); } '''; - document.head.append(externalStyleSheet); + document.head!.append(externalStyleSheet); view = render(react.button({ 'className': 'foo', diff --git a/test/unit/dom/matchers/has_text_content_test.dart b/test/unit/dom/matchers/has_text_content_test.dart index fbf5cdbf..371f2c3a 100644 --- a/test/unit/dom/matchers/has_text_content_test.dart +++ b/test/unit/dom/matchers/has_text_content_test.dart @@ -27,7 +27,7 @@ import '../../util/over_react_stubs.dart'; void main() { group('hasTextContent matcher', () { - Element rootElement; + late Element rootElement; setUp(() { final view = render( diff --git a/test/unit/dom/matchers/has_value_test.dart b/test/unit/dom/matchers/has_value_test.dart index bce1eee5..77d3ed6c 100644 --- a/test/unit/dom/matchers/has_value_test.dart +++ b/test/unit/dom/matchers/has_value_test.dart @@ -30,9 +30,9 @@ void main() { @isTestGroup void sharedHasValueTests(String description, - {@required Matcher Function([dynamic]) matcherFn, String valueDescription = 'value'}) { + {required Matcher Function([dynamic]) matcherFn, String valueDescription = 'value'}) { group(description, () { - RenderResult view; + late RenderResult view; group('passes when the provided value matches the value found in a', () { group('TextInputElement', () { diff --git a/test/unit/dom/matchers/is_focused_test.dart b/test/unit/dom/matchers/is_focused_test.dart index 0cccb39f..9813939f 100644 --- a/test/unit/dom/matchers/is_focused_test.dart +++ b/test/unit/dom/matchers/is_focused_test.dart @@ -27,14 +27,14 @@ void main() { final allAttachedNodes = []; Element makeAttachedNode() { final node = DivElement()..tabIndex = 1; - document.body.append(node); + document.body!.append(node); allAttachedNodes.add(node); return node; } - Element attachedNode; + late Element attachedNode; setUp(() { attachedNode = makeAttachedNode(); diff --git a/test/unit/dom/pretty_dom_test.dart b/test/unit/dom/pretty_dom_test.dart index 1f85cb57..1d04c8b7 100644 --- a/test/unit/dom/pretty_dom_test.dart +++ b/test/unit/dom/pretty_dom_test.dart @@ -23,7 +23,7 @@ import 'package:test/test.dart'; void main() { group('prettyDOM', () { group('returns a formatted string of the HTML produced by the node provided', () { - Ref vDomRootRef; + late Ref vDomRootRef; setUp(() { vDomRootRef = react.createRef(); final vDom = react.div( diff --git a/test/unit/dom/queries/by_label_text_test.dart b/test/unit/dom/queries/by_label_text_test.dart index e59cd2c9..2c6ac580 100644 --- a/test/unit/dom/queries/by_label_text_test.dart +++ b/test/unit/dom/queries/by_label_text_test.dart @@ -29,7 +29,7 @@ void main() { group('', () { initConfigForInternalTesting(); - rtl.RenderResult view; + late rtl.RenderResult view; group( 'the selector argument can be specified to target only matching ' diff --git a/test/unit/dom/queries/by_role_test.dart b/test/unit/dom/queries/by_role_test.dart index ece55d81..fb3dd7a2 100644 --- a/test/unit/dom/queries/by_role_test.dart +++ b/test/unit/dom/queries/by_role_test.dart @@ -29,8 +29,8 @@ void main() { group('', () { initConfigForInternalTesting(); - rtl.RenderResult view; - Ref/*!*/ emptyElementRef; + late rtl.RenderResult view; + Ref emptyElementRef; group('when more than one element has the same role,', () { setUp(() { @@ -765,14 +765,14 @@ ReactElement renderButton({bool pressed = false, bool expanded = false}) { 'aria-expanded': expanded, }, 'Click me', - ) as ReactElement/*!*/; + ) as ReactElement; } ReactElement renderDialog() { return react.div( {'role': 'dialog'}, 'Read me', - ) as ReactElement/*!*/; + ) as ReactElement; } ReactElement renderTab({bool selected = false}) { @@ -783,7 +783,7 @@ ReactElement renderTab({bool selected = false}) { 'aria-selected': selected, }, 'Select me', - ) as ReactElement/*!*/; + ) as ReactElement; } ReactElement renderCheckbox({bool checked = false}) { @@ -794,7 +794,7 @@ ReactElement renderCheckbox({bool checked = false}) { 'aria-checked': checked, }, 'Check me out', - ) as ReactElement/*!*/; + ) as ReactElement; } ReactElement renderCheckboxWithSwitchAsFallback({bool checked = false}) { @@ -805,5 +805,5 @@ ReactElement renderCheckboxWithSwitchAsFallback({bool checked = false}) { 'aria-checked': checked, }, 'Check me out', - ) as ReactElement/*!*/; + ) as ReactElement; } diff --git a/test/unit/dom/queries/by_testid_test.dart b/test/unit/dom/queries/by_testid_test.dart index 01b16f32..96980a45 100644 --- a/test/unit/dom/queries/by_testid_test.dart +++ b/test/unit/dom/queries/by_testid_test.dart @@ -30,7 +30,7 @@ void main() { group('', () { initConfigForInternalTesting(); - rtl.RenderResult view; + late rtl.RenderResult view; group('basic functionality', () { setUp(() { diff --git a/test/unit/dom/queries/by_text_test.dart b/test/unit/dom/queries/by_text_test.dart index 7c1cd2fb..7ab8b7de 100644 --- a/test/unit/dom/queries/by_text_test.dart +++ b/test/unit/dom/queries/by_text_test.dart @@ -29,7 +29,7 @@ void main() { group('', () { initConfigForInternalTesting(); - rtl.RenderResult view; + late rtl.RenderResult view; group( 'the selector argument can be specified to target only matching ' diff --git a/test/unit/dom/queries/shared/scoped_queries_tests.dart b/test/unit/dom/queries/shared/scoped_queries_tests.dart index 5fc1a2c9..8bc9005d 100644 --- a/test/unit/dom/queries/shared/scoped_queries_tests.dart +++ b/test/unit/dom/queries/shared/scoped_queries_tests.dart @@ -31,7 +31,7 @@ import '../../../util/rendering.dart'; import 'text_match_type_parsing_tests.dart'; class ScopedQueriesTestWrapper { - ScopedQueriesTestWrapper(this.queries, [rtl.RenderResult renderResult]) + ScopedQueriesTestWrapper(this.queries, [rtl.RenderResult? renderResult]) : renderResult = renderResult ?? queries as rtl.RenderResult; final ScopedQueries queries; @@ -41,17 +41,17 @@ class ScopedQueriesTestWrapper { @isTestGroup void hasQueriesScopedTo( String scopeName, - ScopedQueriesTestWrapper Function(String scopeName, {bool testAsyncQuery, bool renderMultipleElsMatchingQuery}) + ScopedQueriesTestWrapper Function(String scopeName, {bool? testAsyncQuery, bool? renderMultipleElsMatchingQuery}) getWrapper, {bool isGloballyScoped = true}) { group('$scopeName:', () { - String/*!*/ expectedPrettyDom; + String expectedPrettyDom; initConfigForInternalTesting(); ScopedQueries renderAndGetQueries({ bool testAsyncQuery = false, - bool renderMultipleElsMatchingQuery, + bool? renderMultipleElsMatchingQuery, }) { rtl.RenderResult renderResult; Node getQueryContainer(rtl.RenderResult result) => isGloballyScoped ? result.baseElement : result.container; @@ -63,7 +63,7 @@ void hasQueriesScopedTo( testAsyncQuery: testAsyncQuery, renderMultipleElsMatchingQuery: renderMultipleElsMatchingQuery) .renderResult; - final delayedRenderOfRootNode = querySelector('[$defaultTestIdKey="delayed-render-of-root"]'); + final delayedRenderOfRootNode = querySelector('[$defaultTestIdKey="delayed-render-of-root"]')!; expect(delayedRenderOfRootNode, isNotNull, reason: 'Async queries should be tested on DOM wrapped by / controlled by the DelayedRenderOf component.'); expect(delayedRenderOfRootNode.children, isEmpty, @@ -415,7 +415,7 @@ void hasQueriesScopedTo( test('limiting the scope of the query as expected', () { final outOfScopeElement = DivElement()..text = 'out-of-scope'; - document.body.append(outOfScopeElement); + document.body!.append(outOfScopeElement); addTearDown(outOfScopeElement.remove); final queries = renderAndGetQueries(); diff --git a/test/unit/dom/queries/shared/text_match_type_parsing_tests.dart b/test/unit/dom/queries/shared/text_match_type_parsing_tests.dart index 8cc8a667..486dc34a 100644 --- a/test/unit/dom/queries/shared/text_match_type_parsing_tests.dart +++ b/test/unit/dom/queries/shared/text_match_type_parsing_tests.dart @@ -55,18 +55,18 @@ String getStringThatFuzzyMatches(String exactValue) => exactValue.substring(2); @isTestGroup void testTextMatchTypes( QueryType queryType, { - @required TextMatchArgName textMatchArgName, - @required String queryShouldMatchOn, - @required String Function() getExpectedPrettyDom, - Map scopedQueryQueriesByName = const {}, - Map scopedGetQueriesByName = const {}, - Map scopedFindQueriesByName = const {}, - Map topLevelQueryQueriesByName = const {}, - Map topLevelGetQueriesByName = const {}, - Map topLevelFindQueriesByName = const {}, - Node Function() getContainerForTopLevelQueries, + required TextMatchArgName textMatchArgName, + required String queryShouldMatchOn, + required String Function() getExpectedPrettyDom, + Map scopedQueryQueriesByName = const {}, + Map scopedGetQueriesByName = const {}, + Map scopedFindQueriesByName = const {}, + Map topLevelQueryQueriesByName = const {}, + Map topLevelGetQueriesByName = const {}, + Map topLevelFindQueriesByName = const {}, + Node Function()? getContainerForTopLevelQueries, bool textMatchArgSupportsFuzzyMatching = true, - String failureSnapshotPattern, + String? failureSnapshotPattern, }) { const queryShouldNotMatchOn = 'somethingDifferentThatDoesNotMatch'; @@ -91,7 +91,7 @@ void testTextMatchTypes( assert(getContainerForTopLevelQueries != null); } - Matcher toThrowErrorMatchingInlineSnapshotPattern(String/*!*/ valueExpectedButNotFound) { + Matcher toThrowErrorMatchingInlineSnapshotPattern(String valueExpectedButNotFound) { Matcher containsMatcher; if (failureSnapshotPattern != null) { containsMatcher = buildContainsPatternUsing(failureSnapshotPattern, valueExpectedButNotFound); @@ -125,12 +125,12 @@ void testTextMatchTypes( @isTest void textMatchShouldFailFor< /*TextMatch*/ T>( String queryName, - Function Function({bool renderMultipleElsMatchingQuery}) queryGetter, { - @required T valueThatShouldCauseFailure, + Function Function({bool? renderMultipleElsMatchingQuery}) queryGetter, { + required T valueThatShouldCauseFailure, bool exact = true, bool containerArgRequired = false, - String snapshotPatternForFailureMatcher, - Matcher failureMatcher, + String? snapshotPatternForFailureMatcher, + Matcher? failureMatcher, }) { if (valueThatShouldCauseFailure is String) { snapshotPatternForFailureMatcher ??= valueThatShouldCauseFailure; @@ -140,10 +140,10 @@ void testTextMatchTypes( } test('$queryName query', () async { - String/*!*/ queryFnString; + late String queryFnString; final queryFn = queryGetter(); final container = getContainerForTopLevelQueries?.call(); - dynamic Function() getQueryResult; + late dynamic Function() getQueryResult; if (queryType != QueryType.Role) { getQueryResult = () => containerArgRequired @@ -188,7 +188,7 @@ void testTextMatchTypes( } else { // getBy* / findBy* queries should throw in a failure scenario expect(() => getQueryResult(), - failureMatcher ?? toThrowErrorMatchingInlineSnapshotPattern(snapshotPatternForFailureMatcher), + failureMatcher ?? toThrowErrorMatchingInlineSnapshotPattern(snapshotPatternForFailureMatcher!), reason: '\nCalling the following query should have thrown:\n\n$queryFnString'); } }, timeout: asyncQueryTestTimeout); @@ -197,16 +197,16 @@ void testTextMatchTypes( @isTest void textMatchShouldSucceedFor< /*TextMatch*/ T>( String queryName, - Function Function({bool renderMultipleElsMatchingQuery}) queryGetter, { - @required T valueThatShouldCauseSuccess, + Function Function({bool? renderMultipleElsMatchingQuery}) queryGetter, { + required T valueThatShouldCauseSuccess, bool exact = true, - NormalizerFn Function([NormalizerOptions]) normalizer, + NormalizerFn Function([NormalizerOptions?])? normalizer, bool containerArgRequired = false, }) { - String/*!*/ queryFnString; + late String queryFnString; Function queryFn; - Node/*!*/ container; - dynamic Function() getQueryResult; + Node container; + late dynamic Function() getQueryResult; void sharedSetup({bool renderMultipleElsMatchingQuery = false}) { queryFn = queryGetter(renderMultipleElsMatchingQuery: renderMultipleElsMatchingQuery); diff --git a/test/unit/dom/text_match_test.dart b/test/unit/dom/text_match_test.dart index 0cd0311e..0c55febd 100644 --- a/test/unit/dom/text_match_test.dart +++ b/test/unit/dom/text_match_test.dart @@ -31,7 +31,7 @@ void main() { ------------------------------ Query Failure Stack Trace:'''; - rtl.RenderResult view; + late rtl.RenderResult view; group('ByAltText query', () { const actualText = 'Johnny Be Good'; diff --git a/test/unit/dom/top_level_queries_test.dart b/test/unit/dom/top_level_queries_test.dart index a07321d0..e8f1babc 100644 --- a/test/unit/dom/top_level_queries_test.dart +++ b/test/unit/dom/top_level_queries_test.dart @@ -82,13 +82,13 @@ void main() { group('contains queries that can be scoped to the specified container', () { const scopeName = 'top level'; - Node/*!*/ container; - String/*!*/ expectedPrettyDom; + Node container; + String expectedPrettyDom; Function _renderForQuery( Function query, { bool testAsyncQuery = false, - bool renderMultipleElsMatchingQuery, + bool? renderMultipleElsMatchingQuery, }) { final elsForQuerying = elementsForQuerying(scopeName, renderMultipleElsMatchingQuery: renderMultipleElsMatchingQuery); @@ -100,7 +100,7 @@ void main() { expectedPrettyDom = rtl.prettyDOM(container); if (testAsyncQuery) { - final delayedRenderOfRootNode = querySelector('[$defaultTestIdKey="delayed-render-of-root"]'); + final delayedRenderOfRootNode = querySelector('[$defaultTestIdKey="delayed-render-of-root"]')!; expect(delayedRenderOfRootNode, isNotNull, reason: 'Async queries should be tested on DOM wrapped by / controlled by the DelayedRenderOf component.'); diff --git a/test/unit/dom/wait_for_test.dart b/test/unit/dom/wait_for_test.dart index 5a40d32a..a014db4b 100644 --- a/test/unit/dom/wait_for_test.dart +++ b/test/unit/dom/wait_for_test.dart @@ -32,8 +32,8 @@ void main() { group('', () { initConfigForInternalTesting(); - rtl.RenderResult view; - Element/*!*/ rootElement; + late rtl.RenderResult view; + Element rootElement; group('waitFor()', () { setUp(() { @@ -193,9 +193,9 @@ void main() { }); group('waitForElementToBeRemoved()', () { - Node elementThatWillBeRemovedAfterDelay; - Node elementInDomButOutsideContainer; - Node elementThatWontBeRemoved; + late Node elementThatWillBeRemovedAfterDelay; + late Node elementInDomButOutsideContainer; + late Node elementThatWontBeRemoved; final delayAfterWhichTheElementWillBeRemoved = asyncQueryTimeout ~/ 2; final shortTimeout = asyncQueryTimeout ~/ 4; @@ -218,7 +218,7 @@ void main() { ))) as ReactElement); elementThatWillBeRemovedAfterDelay = view.getByText('willBeRemoved'); elementThatWontBeRemoved = view.getByText('wontBeRemoved'); - elementInDomButOutsideContainer = document.body.append(DivElement() + elementInDomButOutsideContainer = document.body!.append(DivElement() ..id = 'notInScope' ..text = 'notInScope'); }); @@ -264,7 +264,7 @@ void main() { test('null, throws', () async { expect( - () => rtl.waitForElementToBeRemoved(() => null, container: view.container), + () => rtl.waitForElementToBeRemoved((() => null) as Node Function(), container: view.container), throwsA(allOf( isA(), hasToStringValue(contains('The callback must return a non-null Element.')), @@ -284,11 +284,11 @@ void main() { }); group('waitForElementsToBeRemoved()', () { - Node elementThatWillBeRemovedAfterDelay; - Node anotherElementThatWillBeRemovedAfterDelay; - Node elementThatWillNotBeRemovedAfterDelay; - Node elementInDomButOutsideContainer; - Node anotherElementInDomButOutsideContainer; + late Node elementThatWillBeRemovedAfterDelay; + late Node anotherElementThatWillBeRemovedAfterDelay; + late Node elementThatWillNotBeRemovedAfterDelay; + late Node elementInDomButOutsideContainer; + late Node anotherElementInDomButOutsideContainer; final delayAfterWhichTheElementWillBeRemoved = asyncQueryTimeout ~/ 2; final shortTimeout = asyncQueryTimeout ~/ 4; @@ -312,10 +312,10 @@ void main() { elementThatWillBeRemovedAfterDelay = view.getByText('willBeRemoved'); anotherElementThatWillBeRemovedAfterDelay = view.getByText('willAlsoBeRemoved'); elementThatWillNotBeRemovedAfterDelay = view.getByText('willNotBeRemoved'); - elementInDomButOutsideContainer = document.body.append(DivElement() + elementInDomButOutsideContainer = document.body!.append(DivElement() ..id = 'notInScope' ..text = 'notInScope'); - anotherElementInDomButOutsideContainer = document.body.append(DivElement() + anotherElementInDomButOutsideContainer = document.body!.append(DivElement() ..id = 'alsoNotInScope' ..text = 'alsoNotInScope'); }); @@ -438,7 +438,7 @@ void main() { test('null, throws', () async { expect( - () => rtl.waitForElementsToBeRemoved(() => null, container: view.container), + () => rtl.waitForElementsToBeRemoved((() => null) as List Function(), container: view.container), throwsA(allOf( isA(), hasToStringValue(contains('The callback must return one or more non-null Elements.')), diff --git a/test/unit/dom/within_test.dart b/test/unit/dom/within_test.dart index 34f37c02..856d5a65 100644 --- a/test/unit/dom/within_test.dart +++ b/test/unit/dom/within_test.dart @@ -36,7 +36,7 @@ void main() { }) { final elsForQuerying = elementsForQuerying(scopeName, renderMultipleElsMatchingQuery: renderMultipleElsMatchingQuery); - final els = testAsyncQuery + final els = testAsyncQuery! ? DelayedRenderOf({'childrenToRenderAfterDelay': elsForQuerying}) : elsForQuerying; final view = rtl.render(els); diff --git a/test/unit/react/render_test.dart b/test/unit/react/render_test.dart index 989ffba6..c3872ad7 100644 --- a/test/unit/react/render_test.dart +++ b/test/unit/react/render_test.dart @@ -54,7 +54,7 @@ void main() { }) { final elsForQuerying = elementsForQuerying(scopeName, renderMultipleElsMatchingQuery: renderMultipleElsMatchingQuery); - final els = testAsyncQuery + final els = testAsyncQuery! ? DelayedRenderOf({'childrenToRenderAfterDelay': elsForQuerying}) : elsForQuerying; return ScopedQueriesTestWrapper(rtl.render(els)); @@ -93,14 +93,14 @@ void main() { group('renders the provided element in a default container', () { test('', () { final view = rtl.render(react.div({'id': 'root'}, 'oh hai') as ReactElement); - expect(document.body.contains(view.container), isTrue); + expect(document.body!.contains(view.container), isTrue); expect(view.container.childNodes, hasLength(1)); expect(view.container.childNodes.single.text, 'oh hai'); }); test('wrapped in a wrapper when specified', () { rtl.render(react.div({'id': 'root'}, 'oh hai') as ReactElement, wrapper: react.aside); - final wrapperElement = querySelector('aside'); + final wrapperElement = querySelector('aside')!; expect(wrapperElement, isNotNull); expect(wrapperElement.querySelector('#root'), isNotNull); }); @@ -117,7 +117,7 @@ void main() { group('and then unmounts / removes it by default, also calling the provided autoTearDownCallback', () { test('', () { addTearDown(() { - expect(document.body.children, isEmpty); + expect(document.body!.children, isEmpty); expect(calls, ['autoTearDownCallback']); calls.clear(); }); @@ -128,7 +128,7 @@ void main() { }); group('unless autoTearDown is false', () { - rtl.RenderResult view; + late rtl.RenderResult view; tearDownAll(() { view.unmount(); @@ -140,42 +140,42 @@ void main() { }); test('', () { - expect(document.body.children.contains(view.container), isTrue); + expect(document.body!.children.contains(view.container), isTrue); }); }); }); }); group('renders the provided element in the provided container', () { - Node customContainer; + Node? customContainer; test('', () { - customContainer = document.body.append(DivElement()..id = 'custom-container'); + customContainer = document.body!.append(DivElement()..id = 'custom-container'); final renderedResult = rtl.render(react.div({'id': 'root'}, 'oh hai') as ReactElement, container: customContainer); expect(renderedResult.container, same(customContainer)); - expect(document.body.contains(renderedResult.container), isTrue); + expect(document.body!.contains(renderedResult.container), isTrue); expect(renderedResult.container.childNodes, hasLength(1)); expect(renderedResult.container.childNodes.single.text, 'oh hai'); }); group('and then unmounts / removes it by default', () { test('', () { - expect(document.body.children, isEmpty); + expect(document.body!.children, isEmpty); }); group('unless autoTearDown is false', () { - rtl.RenderResult view; + late rtl.RenderResult view; tearDown(() { - expect(document.body.children.contains(view.container), isTrue); + expect(document.body!.children.contains(view.container), isTrue); view.unmount(); view.container.remove(); customContainer = null; }); test('', () { - customContainer = document.body.append(DivElement()..id = 'custom-container'); + customContainer = document.body!.append(DivElement()..id = 'custom-container'); view = rtl.render(react.div({'id': 'root'}, 'oh hai') as ReactElement, container: customContainer, autoTearDown: false); }); @@ -248,7 +248,7 @@ class _PortalComponent extends react.Component2 { @override dynamic componentDidMount() { final toolTip = react.div({'role': 'tooltip'}, ['I Am a Tooltip']); - final portal = ReactDom.createPortal(toolTip, document.body); + final portal = ReactDom.createPortal(toolTip, document.body!); react_dom.render(portal, document.body); } diff --git a/test/unit/user_event/click_test.dart b/test/unit/user_event/click_test.dart index 4f42eb6b..668aee60 100644 --- a/test/unit/user_event/click_test.dart +++ b/test/unit/user_event/click_test.dart @@ -25,9 +25,9 @@ import '../util/event_handler_error.dart'; void main() { group('User click events:', () { - List calls; - int hoverEventCount; - rtl.RenderResult view; + late List calls; + late int hoverEventCount; + late rtl.RenderResult view; setUp(() { calls = []; @@ -36,7 +36,7 @@ void main() { final elementToRender = react.button({ 'id': 'root', 'onClick': (event) { - calls.add((event as react.SyntheticMouseEvent).nativeEvent as MouseEvent/*!*/); + calls.add((event as react.SyntheticMouseEvent).nativeEvent as MouseEvent); }, // Count mouseover events to find out how many hover events occur. 'onMouseOver': (_) => hoverEventCount++, diff --git a/test/unit/user_event/hover_test.dart b/test/unit/user_event/hover_test.dart index 3340e687..d23a73b2 100644 --- a/test/unit/user_event/hover_test.dart +++ b/test/unit/user_event/hover_test.dart @@ -27,8 +27,8 @@ import '../util/event_handler_error.dart'; void main() { group('UserEvent.hover and UserEvent.unhover', () { - List calls; - rtl.RenderResult view; + late List calls; + late rtl.RenderResult view; setUp(() { calls = []; @@ -102,11 +102,11 @@ ReactDartFunctionComponentFactoryProxy HoverTestComponent = react.registerFuncti react.button({ 'onMouseOver': (e) { isShown.set(true); - props['calls'].add((e as react.SyntheticMouseEvent).nativeEvent as MouseEvent/*!*/); + props['calls'].add((e as react.SyntheticMouseEvent).nativeEvent as MouseEvent); }, 'onMouseOut': (e) { isShown.set(false); - props['calls'].add((e as react.SyntheticMouseEvent).nativeEvent as MouseEvent/*!*/); + props['calls'].add((e as react.SyntheticMouseEvent).nativeEvent as MouseEvent); } }, [ 'Hover over me!' diff --git a/test/unit/user_event/paste_test.dart b/test/unit/user_event/paste_test.dart index 470cc18e..926362b2 100644 --- a/test/unit/user_event/paste_test.dart +++ b/test/unit/user_event/paste_test.dart @@ -26,9 +26,9 @@ import '../util/event_handler_error.dart'; void main() { group('UserEvent.paste', () { - List calls; + late List calls; rtl.RenderResult view; - InputElement/*!*/ input; + InputElement input; setUp(() { calls = []; @@ -44,7 +44,7 @@ void main() { setUp(() { final elementToRender = react.input({ 'onPaste': (event) { - calls.add((event as react.SyntheticClipboardEvent).nativeEvent as ClipboardEvent/*!*/); + calls.add((event as react.SyntheticClipboardEvent).nativeEvent as ClipboardEvent); }, }); @@ -70,7 +70,7 @@ void main() { setUp(() { final elementToRender = react.input({ 'onPaste': (event) { - calls.add((event as react.SyntheticClipboardEvent).nativeEvent as ClipboardEvent/*!*/); + calls.add((event as react.SyntheticClipboardEvent).nativeEvent as ClipboardEvent); }, 'defaultValue': 'this is a bad example', }); diff --git a/test/unit/user_event/select_options_test.dart b/test/unit/user_event/select_options_test.dart index 81762a90..c9ed4e7d 100644 --- a/test/unit/user_event/select_options_test.dart +++ b/test/unit/user_event/select_options_test.dart @@ -27,9 +27,9 @@ void main() { group('User select/deselect events:', () { group('UserEvent.selectOptions', () { void _selectOptionsTestHelper({bool isMultiSelect = false}) { - List calls; - SelectElement select; - rtl.RenderResult view; + late List calls; + late SelectElement select; + late rtl.RenderResult view; setUp(() { calls = []; @@ -37,7 +37,7 @@ void main() { view = rtl.render(react.select({ 'id': 'root', 'onClick': (event) { - calls.add((event as react.SyntheticMouseEvent).nativeEvent as MouseEvent/*!*/); + calls.add((event as react.SyntheticMouseEvent).nativeEvent as MouseEvent); }, 'multiple': isMultiSelect, }, [ @@ -134,9 +134,9 @@ void main() { }); group('UserEvent.deselectOptions', () { - List calls; - SelectElement select; - rtl.RenderResult view; + late List calls; + late SelectElement select; + late rtl.RenderResult view; setUp(() { calls = []; @@ -144,7 +144,7 @@ void main() { view = rtl.render(react.select({ 'id': 'root', 'onClick': (event) { - calls.add((event as react.SyntheticMouseEvent).nativeEvent as MouseEvent/*!*/); + calls.add((event as react.SyntheticMouseEvent).nativeEvent as MouseEvent); }, 'multiple': true, 'defaultValue': ['1', '2', '3'], diff --git a/test/unit/user_event/special_chars_test.dart b/test/unit/user_event/special_chars_test.dart index b64c4971..233fda86 100644 --- a/test/unit/user_event/special_chars_test.dart +++ b/test/unit/user_event/special_chars_test.dart @@ -24,10 +24,10 @@ import 'package:test/test.dart'; void main() { group('SpecialChars', () { - InputElement input; - TextAreaElement textArea; + late InputElement input; + late TextAreaElement textArea; rtl.RenderResult view; - List keyDownCalls; + late List keyDownCalls; setUp(() { keyDownCalls = []; diff --git a/test/unit/user_event/tab_test.dart b/test/unit/user_event/tab_test.dart index 613f0d54..2aeff9d9 100644 --- a/test/unit/user_event/tab_test.dart +++ b/test/unit/user_event/tab_test.dart @@ -27,8 +27,8 @@ import '../util/over_react_stubs.dart'; void main() { group('UserEvent.tab events:', () { - rtl.RenderResult view; - List/*!*/ inputs; + late rtl.RenderResult view; + List inputs; group('', () { setUp(() { diff --git a/test/unit/user_event/type_test.dart b/test/unit/user_event/type_test.dart index 056f3990..e047d24d 100644 --- a/test/unit/user_event/type_test.dart +++ b/test/unit/user_event/type_test.dart @@ -60,9 +60,9 @@ void main() { } void _typeTestHelper({bool hasDelay = false, bool isTextArea = false}) { - int/*!*/ clickEventCount; - Element/*!*/ element; - List keyUpCalls; + int clickEventCount; + Element element; + late List keyUpCalls; rtl.RenderResult view; void _verifyTypeEvent({ @@ -77,9 +77,9 @@ void _typeTestHelper({bool hasDelay = false, bool isTextArea = false}) { int delay, { bool skipClick = false, bool skipAutoClose = false, - int initialSelectionStart, - int initialSelectionEnd, - int charsTyped, + int? initialSelectionStart, + int? initialSelectionEnd, + int? charsTyped, }) async { charsTyped ??= text.length; final timer = Stopwatch(); @@ -218,7 +218,7 @@ void _typeTestHelper({bool hasDelay = false, bool isTextArea = false}) { await UserEvent.typeWithDelay( view.getByTestId('event-handle-error-tester'), stringToTest, Duration(milliseconds: 250)); }, - throwsA(predicate((e) { + throwsA(predicate((dynamic e) { return e is Exception && e.toString().contains('Multiple errors (${stringToTest.length})'); })), ); @@ -287,9 +287,9 @@ void _typeTestHelper({bool hasDelay = false, bool isTextArea = false}) { } void _keyboardTestHelper({bool hasDelay = false}) { - List calls; + late List calls; rtl.RenderResult view; - InputElement input; + late InputElement input; setUp(() { calls = []; @@ -298,9 +298,9 @@ void _keyboardTestHelper({bool hasDelay = false}) { Future _verifyKeyboardWithDelay( String text, int delay, { - KeyboardState keyboardState, - List keyboardMap, - int charsTyped, + KeyboardState? keyboardState, + List? keyboardMap, + int? charsTyped, }) async { charsTyped ??= text.length; final timer = Stopwatch(); diff --git a/test/unit/user_event/upload_test.dart b/test/unit/user_event/upload_test.dart index 22952406..aa7a2565 100644 --- a/test/unit/user_event/upload_test.dart +++ b/test/unit/user_event/upload_test.dart @@ -26,11 +26,11 @@ import '../util/event_handler_error.dart'; void main() { group('UserEvent.upload', () { void _uploadTestHelper({bool isMultiple = false}) { - List clickEventCalls; - List changeEventCalls; - FileUploadInputElement input; - LabelElement label; - List files; + late List clickEventCalls; + late List changeEventCalls; + late FileUploadInputElement input; + late LabelElement label; + late List files; setUp(() { files = isMultiple @@ -49,10 +49,10 @@ void main() { 'id': 'file-uploader', 'type': 'file', 'onClick': (e) { - clickEventCalls.add((e as react.SyntheticMouseEvent).nativeEvent as MouseEvent/*!*/); + clickEventCalls.add((e as react.SyntheticMouseEvent).nativeEvent as MouseEvent); }, 'onChange': (e) { - changeEventCalls.add((e as react.SyntheticFormEvent).nativeEvent as Event/*!*/); + changeEventCalls.add((e as react.SyntheticFormEvent).nativeEvent as Event); }, 'multiple': isMultiple, 'accept': '.png,.jpeg', @@ -72,18 +72,18 @@ void main() { }) { if (isMultiple && applyAccept) { expect(input.files, hasLength(2), reason: 'file1 is not an image'); - expect(input.files.first.name, 'file2.png'); - expect(input.files[1].name, 'file3.jpeg'); + expect(input.files!.first.name, 'file2.png'); + expect(input.files![1].name, 'file3.jpeg'); } else if (isMultiple) { expect(input.files, hasLength(3)); - expect(input.files.first.name, 'file1.mp3'); - expect(input.files[1].name, 'file2.png'); - expect(input.files[2].name, 'file3.jpeg'); + expect(input.files!.first.name, 'file1.mp3'); + expect(input.files![1].name, 'file2.png'); + expect(input.files![2].name, 'file3.jpeg'); } else if (applyAccept) { expect(input.files, hasLength(0), reason: 'file1 is not an image'); } else { expect(input.files, hasLength(1)); - expect(input.files.first.name, 'file1.mp3'); + expect(input.files!.first.name, 'file1.mp3'); } // Don't check click/change events if `accept` is applied for single file diff --git a/test/unit/util/event_handler_error.dart b/test/unit/util/event_handler_error.dart index 292027f4..7d4aaf3c 100644 --- a/test/unit/util/event_handler_error.dart +++ b/test/unit/util/event_handler_error.dart @@ -50,7 +50,7 @@ void testEventHandlerErrors( expect( () => userEventTrigger(view.getByTestId(targetTestId)), - throwsA(predicate((e) { + throwsA(predicate((dynamic e) { return e is Exception && e.toString().contains('Multiple errors'); })), ); diff --git a/test/unit/util/init.dart b/test/unit/util/init.dart index 76b2070c..605631ac 100644 --- a/test/unit/util/init.dart +++ b/test/unit/util/init.dart @@ -21,8 +21,8 @@ import 'package:test/test.dart'; import 'constants.dart'; -void initConfigForInternalTesting([Function() additionalSetup]) { - JsConfig/*!*/ initialConfig; +void initConfigForInternalTesting([Function()? additionalSetup]) { + JsConfig initialConfig; setUpAll(() { initialConfig = rtl.getConfig(); @@ -38,6 +38,6 @@ void initConfigForInternalTesting([Function() additionalSetup]) { throwSuggestions: false, asyncUtilTimeout: asyncQueryTimeout.inMilliseconds, ); - expect(document.body.children, isEmpty); + expect(document.body!.children, isEmpty); }); } diff --git a/test/unit/util/matchers.dart b/test/unit/util/matchers.dart index c451087a..a6f7bdcd 100644 --- a/test/unit/util/matchers.dart +++ b/test/unit/util/matchers.dart @@ -23,7 +23,7 @@ class _HasToStringValue extends CustomMatcher { _HasToStringValue(matcher) : super('Object with toString() value', 'toString()', matcher); @override - dynamic featureValueOf(Object item) => item.toString(); + dynamic featureValueOf(Object? item) => item.toString(); } /// Returns a matcher that matches an object whose `toString` value matches [value]. @@ -32,9 +32,9 @@ Matcher hasToStringValue(dynamic value) => _HasToStringValue(value); Matcher toThrowErrorMatchingInlineSnapshot( Matcher stringSnapshotMatcher, Matcher stringPrettyDomMatcher, [ - Matcher arbitraryMatcher1, - Matcher arbitraryMatcher2, - Matcher arbitraryMatcher3, + Matcher? arbitraryMatcher1, + Matcher? arbitraryMatcher2, + Matcher? arbitraryMatcher3, ]) { final errorNameMatcher = hasToStringValue(contains('TestingLibraryElementError')); final snapshotMatcher = hasToStringValue(stringSnapshotMatcher); @@ -123,7 +123,7 @@ void shouldFail(dynamic value, Matcher matcher, dynamic expected, {bool useDoubl if (expected is String) { expect(_errorString, equalsIgnoringWhitespace(expected)); } else { - var escapedErrorString = _errorString.replaceAll(RegExp(r'[\s\n]+'), ' '); + var escapedErrorString = _errorString!.replaceAll(RegExp(r'[\s\n]+'), ' '); if (useDoubleQuotes) { escapedErrorString = escapedErrorString.replaceAll("\'", '"'); } @@ -137,6 +137,6 @@ void shouldFail(dynamic value, Matcher matcher, dynamic expected, {bool useDoubl /// Utility for asserting that [matcher] will pass on [value]. /// /// Copyright (c) 2012, the Dart project authors. -void shouldPass(dynamic value, Matcher matcher, {String reason}) { +void shouldPass(dynamic value, Matcher matcher, {String? reason}) { expect(value, matcher, reason: reason); } diff --git a/test/unit/util/over_react_stubs.dart b/test/unit/util/over_react_stubs.dart index e3294a0c..94b58b45 100644 --- a/test/unit/util/over_react_stubs.dart +++ b/test/unit/util/over_react_stubs.dart @@ -43,7 +43,7 @@ external ReactElement _cloneElement(element, [props, children]); /// > Unlike React.addons.cloneWithProps, key and ref from the original element will be preserved. /// > There is no special behavior for merging any props (unlike cloneWithProps). /// > See the [v0.13 RC2 blog post](https://facebook.github.io/react/blog/2015/03/03/react-v0.13-rc2.html) for additional details. -ReactElement cloneElement(ReactElement element, [Map props, Iterable children]) { +ReactElement cloneElement(ReactElement element, [Map? props, Iterable? children]) { if (element == null) throw ArgumentError.notNull('element'); final propsChangeset = preparePropsChangeset(element, props, children); @@ -66,7 +66,7 @@ ReactElement cloneElement(ReactElement element, [Map props, Iterable children]) /// * Children are likewise copied and potentially overwritten with [newChildren] as expected. /// * For JS components, a JS copy of [newProps] is returned, since React will merge the props without any special handling. /// If these values might contain event handlers -dynamic preparePropsChangeset(ReactElement element, Map newProps, [Iterable newChildren]) { +dynamic preparePropsChangeset(ReactElement element, Map? newProps, [Iterable? newChildren]) { final type = element.type; final dartComponentVersion = ReactDartComponentVersion.fromType(type); // ignore: invalid_use_of_protected_member diff --git a/test/unit/util/prints_and_logs_recording.dart b/test/unit/util/prints_and_logs_recording.dart index 702591fb..87ea08d0 100644 --- a/test/unit/util/prints_and_logs_recording.dart +++ b/test/unit/util/prints_and_logs_recording.dart @@ -28,7 +28,7 @@ List recordPrintCalls(void Function() callback) { /// Runs a provided [callback] and returns the print statements captured during the runtime /// of that function, and also catches errors. -void spyOnPrintCalls(void Function() callback, {@required void Function(String) onPrint}) { +void spyOnPrintCalls(void Function() callback, {required void Function(String) onPrint}) { // Bind to the current zone so the callback isn't called in our child zone. final boundOnPrint = Zone.current.bindUnaryCallback(onPrint); Zone.current.fork(specification: ZoneSpecification( diff --git a/test/unit/util/rendering.dart b/test/unit/util/rendering.dart index 5304bfc1..dde77f20 100644 --- a/test/unit/util/rendering.dart +++ b/test/unit/util/rendering.dart @@ -26,7 +26,7 @@ import 'shadow_dom.dart'; const validRoleInDom = 'button'; const validRoleNotInDom = 'tablist'; -ReactElement elementsForQuerying(String uniqueName, {bool renderMultipleElsMatchingQuery}) { +ReactElement elementsForQuerying(String uniqueName, {bool? renderMultipleElsMatchingQuery}) { ReactElement renderEls(String _uniqueName) { _uniqueName ??= uniqueName; return react.div( @@ -61,7 +61,7 @@ ReactElement elementsForQuerying(String uniqueName, {bool renderMultipleElsMatch {}, react.button({'type': 'button'}, _uniqueName), ), - ) as ReactElement/*!*/; + ) as ReactElement; } renderMultipleElsMatchingQuery ??= false; @@ -71,7 +71,7 @@ ReactElement elementsForQuerying(String uniqueName, {bool renderMultipleElsMatch {}, renderEls(uniqueName), renderEls('2$uniqueName'), - ) as ReactElement/*!*/; + ) as ReactElement; } return renderEls(uniqueName); @@ -81,8 +81,8 @@ ReactElement elementsForQuerying(String uniqueName, {bool renderMultipleElsMatch final DelayedRenderOf = react.registerFunctionComponent(_DelayedRenderOf, displayName: 'DelayedRenderOf'); _DelayedRenderOf(Map props) { - final delay = props['delay'] as Duration ?? asyncQueryTimeout; - final onDidRenderAfterDelay = props['onDidRenderAfterDelay'] as void Function(); + final delay = props['delay'] as Duration? ?? asyncQueryTimeout; + final onDidRenderAfterDelay = props['onDidRenderAfterDelay'] as void Function()?; final shouldRenderUpdatedChildren = useState(delay == Duration.zero); useEffect(() { diff --git a/test/unit/util/shadow_dom.dart b/test/unit/util/shadow_dom.dart index 53edfa98..c2dd12e8 100644 --- a/test/unit/util/shadow_dom.dart +++ b/test/unit/util/shadow_dom.dart @@ -30,8 +30,8 @@ final ShadowNested = react.forwardRef2((props, ref) { useEffect(() { final shadowRootFirstChild = DivElement() - ..dataset['test-id'] = props['shadowRootFirstChildTestId'] as String ?? 'shadowRootFirstChild'; - divRef.current.attachShadow({'mode': 'open'}).append(shadowRootFirstChild); + ..dataset['test-id'] = props['shadowRootFirstChildTestId'] as String? ?? 'shadowRootFirstChild'; + divRef.current!.attachShadow({'mode': 'open'}).append(shadowRootFirstChild); react_dom.render(react.Fragment({}, props['children']), shadowRootFirstChild); return () => react_dom.unmountComponentAtNode(shadowRootFirstChild); }, const []); From e6794d3a9eb1c02acd5626c0020531a8890278e9 Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Fri, 16 Jun 2023 11:31:14 -0500 Subject: [PATCH 04/31] Fix warnings and lints --- lib/src/dom/async/wait_for.dart | 2 + lib/src/dom/config/configure.dart | 2 +- lib/src/dom/queries/by_testid.dart | 1 - lib/src/dom/queries/interface.dart | 3 +- .../matchers/jest_dom/has_description.dart | 2 +- lib/src/matchers/jest_dom/is_disabled.dart | 2 +- .../matchers/jest_dom/is_in_the_document.dart | 1 + lib/src/react/render/render.dart | 2 +- lib/src/user_event/user_event.dart | 4 +- lib/src/util/console_log_formatter.dart | 3 -- lib/src/util/console_log_utils.dart | 7 ++- lib/src/util/is_or_contains.dart | 1 + test/unit/console_log_utils_test.dart | 43 +++++++++---------- .../dom/matchers/contains_element_test.dart | 9 ---- .../dom/matchers/has_form_values_test.dart | 1 - test/unit/dom/matchers/has_styles_test.dart | 2 +- test/unit/dom/queries/by_role_test.dart | 2 +- .../queries/shared/scoped_queries_tests.dart | 4 +- .../shared/text_match_type_parsing_tests.dart | 4 +- test/unit/dom/top_level_queries_test.dart | 6 +-- test/unit/dom/wait_for_test.dart | 20 +-------- test/unit/react/render_test.dart | 7 ++- test/unit/user_event/paste_test.dart | 2 +- test/unit/user_event/tab_test.dart | 2 +- test/unit/user_event/type_test.dart | 6 +-- test/unit/util/init.dart | 2 +- test/unit/util/matchers.dart | 1 + test/unit/util/over_react_stubs.dart | 1 + test/unit/util/prints_and_logs_recording.dart | 1 - test/unit/util/rendering.dart | 1 - 30 files changed, 56 insertions(+), 88 deletions(-) diff --git a/lib/src/dom/async/wait_for.dart b/lib/src/dom/async/wait_for.dart index 83aef6b9..465ef0ae 100644 --- a/lib/src/dom/async/wait_for.dart +++ b/lib/src/dom/async/wait_for.dart @@ -169,6 +169,7 @@ Future waitForElementToBeRemoved( timeout ??= Duration(milliseconds: config.asyncUtilTimeout); final el = callback(); + // ignore: unnecessary_null_comparison if (el == null) { throw TestingLibraryElementError('The callback must return a non-null Element.'); } @@ -224,6 +225,7 @@ Future waitForElementsToBeRemoved( container ??= document.body; final els = callback(); + // ignore: unnecessary_null_comparison if (els == null || els.isEmpty) { throw TestingLibraryElementError('The callback must return one or more non-null Elements.'); } diff --git a/lib/src/dom/config/configure.dart b/lib/src/dom/config/configure.dart index 8ca40202..4d51267f 100644 --- a/lib/src/dom/config/configure.dart +++ b/lib/src/dom/config/configure.dart @@ -37,7 +37,7 @@ void configure({ TestingLibraryElementError Function(Object message, Element container)? getElementError, }) { JsError _getJsGetElementError(Object message, Element container) { - final dartError = allowInterop(getElementError)!(message, container); + final dartError = allowInterop(getElementError!)(message, container); return buildJsGetElementError(dartError.message, container); } diff --git a/lib/src/dom/queries/by_testid.dart b/lib/src/dom/queries/by_testid.dart index c8d866f4..b5fff782 100644 --- a/lib/src/dom/queries/by_testid.dart +++ b/lib/src/dom/queries/by_testid.dart @@ -34,7 +34,6 @@ library react_testing_library.src.dom.queries.by_testid; import 'dart:html' show Element, Node; import 'package:js/js.dart'; -import 'package:meta/meta.dart'; import 'package:react_testing_library/src/dom/async/types.dart'; import 'package:react_testing_library/src/dom/async/wait_for.dart'; diff --git a/lib/src/dom/queries/interface.dart b/lib/src/dom/queries/interface.dart index 84fca9eb..bc5d9c21 100644 --- a/lib/src/dom/queries/interface.dart +++ b/lib/src/dom/queries/interface.dart @@ -54,8 +54,7 @@ mixin IQueries { if (timeout != null) waitForOptions.timeout = timeout.inMilliseconds; if (interval != null) waitForOptions.interval = interval.inMilliseconds; if (onTimeout != null) waitForOptions.onTimeout = allowInterop(onTimeout); - // ignore: invalid_use_of_protected_member - if (mutationObserverOptions != null) waitForOptions.mutationObserverOptions = mutationObserverOptions.toJs(); + waitForOptions.mutationObserverOptions = mutationObserverOptions.toJs(); return waitForOptions; } diff --git a/lib/src/matchers/jest_dom/has_description.dart b/lib/src/matchers/jest_dom/has_description.dart index aafe9bca..6a98883a 100644 --- a/lib/src/matchers/jest_dom/has_description.dart +++ b/lib/src/matchers/jest_dom/has_description.dart @@ -106,7 +106,7 @@ class _HasDescription extends CustomMatcher with ElementTextContentMatcherMixin dynamic featureValueOf(dynamic item) { final elementsWithDescriptions = _elementsThatDescribe(item); - if (elementsWithDescriptions?.isEmpty ?? true) return null; + if (elementsWithDescriptions.isEmpty) return null; return elementsWithDescriptions .map((el) => ElementTextContentMatcherMixin.getNormalizedTextContentOf(el, normalizeWhitespace: normalizeWhitespace)) diff --git a/lib/src/matchers/jest_dom/is_disabled.dart b/lib/src/matchers/jest_dom/is_disabled.dart index b23ac32b..8d6cfcec 100644 --- a/lib/src/matchers/jest_dom/is_disabled.dart +++ b/lib/src/matchers/jest_dom/is_disabled.dart @@ -89,7 +89,7 @@ class _IsDisabled extends Matcher { if (!isElementThatCanBeDisabled(item, matchState)) return false; final formAncestor = (item as Element).closest('form'); if (formAncestor != null && (formAncestor as FormElement).hasAttribute('disabled')) return true; - return item.disabled as bool; + return (item as ButtonElement).disabled; } void setMatchState(dynamic item, Map matchState) { diff --git a/lib/src/matchers/jest_dom/is_in_the_document.dart b/lib/src/matchers/jest_dom/is_in_the_document.dart index d8ff2adb..0ceafc38 100644 --- a/lib/src/matchers/jest_dom/is_in_the_document.dart +++ b/lib/src/matchers/jest_dom/is_in_the_document.dart @@ -77,6 +77,7 @@ class _IsInTheDocument extends Matcher { @override bool matches(dynamic item, Map matchState) { if (item is! Element) return false; + // ignore: unnecessary_null_comparison return item != null && item.ownerDocument == item.getRootNode({'composed': true}); } diff --git a/lib/src/react/render/render.dart b/lib/src/react/render/render.dart index 57ef0bc3..03d963fa 100644 --- a/lib/src/react/render/render.dart +++ b/lib/src/react/render/render.dart @@ -144,7 +144,7 @@ RenderResult render( if (autoTearDown) { addTearDown(() { jsResult.unmount(); - jsResult.container?.remove(); + jsResult.container.remove(); onDidTearDown?.call(); }); } diff --git a/lib/src/user_event/user_event.dart b/lib/src/user_event/user_event.dart index 7c08ee1b..44039b22 100644 --- a/lib/src/user_event/user_event.dart +++ b/lib/src/user_event/user_event.dart @@ -441,7 +441,7 @@ abstract class UserEvent { element, text, jsifyAndAllowInterop(options), - )); + ) as Object); }); } @@ -632,7 +632,7 @@ abstract class UserEvent { return promiseToFuture(getProperty(_userEvent, 'keyboard')( text, jsifyAndAllowInterop(options), - )); + ) as Object); }); } diff --git a/lib/src/util/console_log_formatter.dart b/lib/src/util/console_log_formatter.dart index 8780b196..ba2eea50 100644 --- a/lib/src/util/console_log_formatter.dart +++ b/lib/src/util/console_log_formatter.dart @@ -48,7 +48,6 @@ String format(dynamic f, List arguments) { } var str = ''; - if (f is String) { var i = 0; final len = arguments.length; str += f.replaceAllMapped(_formatRegExp, (m) { @@ -71,7 +70,6 @@ String format(dynamic f, List arguments) { } catch (_) { return '[Circular]'; } - break; default: return x!; } @@ -80,7 +78,6 @@ String format(dynamic f, List arguments) { if (i < len) { str += ' ${arguments.skip(i).join(' ')}'; } - } return str; } diff --git a/lib/src/util/console_log_utils.dart b/lib/src/util/console_log_utils.dart index 6a85353d..215228e8 100644 --- a/lib/src/util/console_log_utils.dart +++ b/lib/src/util/console_log_utils.dart @@ -18,7 +18,6 @@ library console_log_utils; import 'dart:async'; import 'dart:html'; -import 'dart:js'; import 'dart:js_util'; import 'package:js/js.dart'; @@ -98,7 +97,7 @@ void Function() startSpyingOnConsoleLogs({ final logTypeToCapture = configuration.logType == 'all' ? ConsoleConfig.types : [configuration.logType]; final consoleRefs = {}; final consolePropertyDescriptors = {}; - final _console = getProperty(window, 'console'); + final _console = getProperty(window, 'console') as Object; _resetPropTypeWarningCache(); @@ -131,7 +130,7 @@ void Function() startSpyingOnConsoleLogs({ final args = [arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10] ..removeWhere((arg) => arg == _undefined); boundOnLog(format(message, args)); - _jsFunctionApply(consoleRefs[config], [message, ...args], thisArg: self); + _jsFunctionApply(consoleRefs[config] as Object, [message, ...args], thisArg: self); }) }), ); @@ -185,7 +184,7 @@ class ConsoleConfig { static const ConsoleConfig all = ConsoleConfig._('all'); } -dynamic _jsFunctionApply(dynamic jsFunction, List args, {dynamic thisArg}) { +dynamic _jsFunctionApply(Object jsFunction, List args, {dynamic thisArg}) { return callMethod(jsFunction, 'apply', [thisArg, jsify(args)]); } diff --git a/lib/src/util/is_or_contains.dart b/lib/src/util/is_or_contains.dart index bda1e669..96f838eb 100644 --- a/lib/src/util/is_or_contains.dart +++ b/lib/src/util/is_or_contains.dart @@ -18,4 +18,5 @@ import 'dart:html' show Node; /// Returns whether [root] is the same as or contains the [other] node. /// /// Returns false if either [root] or [other] is null. +// ignore: unnecessary_null_comparison bool isOrContains(Node root, Node other) => (root != null && other != null) && (root == other || root.contains(other)); diff --git a/test/unit/console_log_utils_test.dart b/test/unit/console_log_utils_test.dart index e96e8e59..5170814c 100644 --- a/test/unit/console_log_utils_test.dart +++ b/test/unit/console_log_utils_test.dart @@ -18,7 +18,6 @@ import 'dart:html'; import 'dart:js_util'; import 'package:react/react.dart' as react; -import 'package:react/react_client/react_interop.dart'; import 'package:react_testing_library/src/util/console_log_utils.dart'; import 'package:react_testing_library/react_testing_library.dart' as rtl; import 'package:test/test.dart'; @@ -234,7 +233,7 @@ void main() { group('captures all logs correctly', () { test('when mounting', () { - final logs = recordConsoleLogs(() => rtl.render(Sample({}) as ReactElement)); + final logs = recordConsoleLogs(() => rtl.render(Sample({}))); final expectedLogs = [ contains('Logging a standard log'), contains('A second warning'), @@ -259,9 +258,9 @@ void main() { }); test('when re-rendering', () { - final view = rtl.render(Sample({'shouldAlwaysBeFalse': true}) as ReactElement); + final view = rtl.render(Sample({'shouldAlwaysBeFalse': true})); - final logs = recordConsoleLogs(() => view.rerender(Sample({}) as ReactElement)); + final logs = recordConsoleLogs(() => view.rerender(Sample({}))); final expectedLogs = [ contains('Logging a standard log'), contains('A second warning'), @@ -276,12 +275,12 @@ void main() { }); test('with nested components', () { - final logs = recordConsoleLogs(() => rtl.render(Sample({}, Sample2({})) as ReactElement)); + final logs = recordConsoleLogs(() => rtl.render(Sample({}, Sample2({})))); expect(logs, hasLength(runtimeSupportsPropTypeWarnings() ? 12 : 8)); }); test('with nested components that are the same', () { - final logs = recordConsoleLogs(() => rtl.render(Sample({}, Sample({})) as ReactElement)); + final logs = recordConsoleLogs(() => rtl.render(Sample({}, Sample({})))); expect(logs, hasLength(runtimeSupportsPropTypeWarnings() ? 10 : 8)); }); }); @@ -290,7 +289,7 @@ void main() { group('captures errors correctly', () { test('when mounting', () { final logs = recordConsoleLogs( - () => rtl.render(Sample({'shouldAlwaysBeFalse': true}) as ReactElement), + () => rtl.render(Sample({'shouldAlwaysBeFalse': true})), configuration: ConsoleConfig.error, ); @@ -304,11 +303,11 @@ void main() { test('when re-rendering', () { // Will cause one error - final view = rtl.render(Sample({'shouldAlwaysBeFalse': true}) as ReactElement); + final view = rtl.render(Sample({'shouldAlwaysBeFalse': true})); // Should clear the error from mounting and not create any more final logs = recordConsoleLogs( - () => view.rerender(Sample({'shouldNeverBeNull': true}) as ReactElement), + () => view.rerender(Sample({'shouldNeverBeNull': true})), configuration: ConsoleConfig.error, ); @@ -316,7 +315,7 @@ void main() { }); test('with nested components', () { - final logs = recordConsoleLogs(() => rtl.render(Sample({}, Sample2({})) as ReactElement), + final logs = recordConsoleLogs(() => rtl.render(Sample({}, Sample2({}))), configuration: ConsoleConfig.error); expect( @@ -329,7 +328,7 @@ void main() { test('with nested components that are the same', () { final logs = recordConsoleLogs( - () => rtl.render(Sample({}, Sample({})) as ReactElement), + () => rtl.render(Sample({}, Sample({}))), configuration: ConsoleConfig.error, ); @@ -345,7 +344,7 @@ void main() { group('captures logs correctly', () { test('when mounting', () { - final logs = recordConsoleLogs(() => rtl.render(Sample({}) as ReactElement), configuration: ConsoleConfig.log); + final logs = recordConsoleLogs(() => rtl.render(Sample({})), configuration: ConsoleConfig.log); if (runtimeSupportsPropTypeWarnings()) { expect( @@ -363,11 +362,11 @@ void main() { test('when re-rendering', () { // Will cause one log - final view = rtl.render(Sample({}) as ReactElement); + final view = rtl.render(Sample({})); // Should clear the previous log and result in there being two final logs = recordConsoleLogs( - () => view.rerender(Sample({'addExtraLogAndWarn': true}) as ReactElement), + () => view.rerender(Sample({'addExtraLogAndWarn': true})), configuration: ConsoleConfig.log, ); @@ -381,7 +380,7 @@ void main() { test('with nested components', () { final logs = recordConsoleLogs( - () => rtl.render(Sample({}, Sample2({})) as ReactElement), + () => rtl.render(Sample({}, Sample2({}))), configuration: ConsoleConfig.log, ); @@ -409,7 +408,7 @@ void main() { test('with nested components that are the same', () { final logs = recordConsoleLogs( - () => rtl.render(Sample({}, Sample({})) as ReactElement), + () => rtl.render(Sample({}, Sample({}))), configuration: ConsoleConfig.log, ); @@ -437,7 +436,7 @@ void main() { group('captures warnings correctly', () { test('when mounting', () { - final logs = recordConsoleLogs(() => rtl.render(Sample({}) as ReactElement), configuration: ConsoleConfig.warn); + final logs = recordConsoleLogs(() => rtl.render(Sample({})), configuration: ConsoleConfig.warn); expect( logs, @@ -450,11 +449,11 @@ void main() { test('when re-rendering', () { // Will three warnings - final view = rtl.render(Sample({}) as ReactElement); + final view = rtl.render(Sample({})); // Should clear the previous warnings and result in there being 3 final logs = recordConsoleLogs( - () => view.rerender(Sample({'addExtraLogAndWarn': true}) as ReactElement), + () => view.rerender(Sample({'addExtraLogAndWarn': true})), configuration: ConsoleConfig.warn, ); @@ -469,7 +468,7 @@ void main() { test('with nested components', () { final logs = recordConsoleLogs( - () => rtl.render(Sample({}, Sample2({})) as ReactElement), + () => rtl.render(Sample({}, Sample2({}))), configuration: ConsoleConfig.warn, ); @@ -478,7 +477,7 @@ void main() { test('with nested components that are the same', () { final logs = recordConsoleLogs( - () => rtl.render(Sample({}, Sample({})) as ReactElement), + () => rtl.render(Sample({}, Sample({}))), configuration: ConsoleConfig.warn, ); @@ -497,7 +496,7 @@ void main() { // Don't use recordConsoleLogs since we can't get the returned logs if this throws final logs = []; try { - spyOnConsoleLogs(() => rtl.render(Sample({'shouldErrorInRender': true}) as ReactElement), + spyOnConsoleLogs(() => rtl.render(Sample({'shouldErrorInRender': true})), configuration: ConsoleConfig.error, onLog: logs.add); } catch (_) {} expect(logs, hasLength(2)); diff --git a/test/unit/dom/matchers/contains_element_test.dart b/test/unit/dom/matchers/contains_element_test.dart index 36d10a01..14f9788d 100644 --- a/test/unit/dom/matchers/contains_element_test.dart +++ b/test/unit/dom/matchers/contains_element_test.dart @@ -58,15 +58,6 @@ void main() { final descendant = view.getByTestId('descendant'); shouldFail(descendant, containsElement(ancestor), contains('Which: does not contain $ancestor.')); }); - - test('the descendant argument is null', () { - expect( - () => containsElement(null), - throwsA(allOf( - isA(), - hasToStringValue(contains('Invalid argument(s) (descendant): Must not be null')), - ))); - }); }); }); } diff --git a/test/unit/dom/matchers/has_form_values_test.dart b/test/unit/dom/matchers/has_form_values_test.dart index 59c348a9..b2da1bfe 100644 --- a/test/unit/dom/matchers/has_form_values_test.dart +++ b/test/unit/dom/matchers/has_form_values_test.dart @@ -15,7 +15,6 @@ import 'dart:convert'; -import 'package:meta/meta.dart'; import 'package:react/react.dart' as react; import 'package:react/react_client.dart' show ReactElement; import 'package:react_testing_library/matchers.dart' show hasFormValues; diff --git a/test/unit/dom/matchers/has_styles_test.dart b/test/unit/dom/matchers/has_styles_test.dart index c61a1a32..c2bacc3f 100644 --- a/test/unit/dom/matchers/has_styles_test.dart +++ b/test/unit/dom/matchers/has_styles_test.dart @@ -30,7 +30,7 @@ void main() { late StyleElement externalStyleSheet; tearDown(() { - externalStyleSheet?.remove(); + externalStyleSheet.remove(); }); setUp(() { diff --git a/test/unit/dom/queries/by_role_test.dart b/test/unit/dom/queries/by_role_test.dart index fb3dd7a2..59fdb00f 100644 --- a/test/unit/dom/queries/by_role_test.dart +++ b/test/unit/dom/queries/by_role_test.dart @@ -30,7 +30,7 @@ void main() { initConfigForInternalTesting(); late rtl.RenderResult view; - Ref emptyElementRef; + late Ref emptyElementRef; group('when more than one element has the same role,', () { setUp(() { diff --git a/test/unit/dom/queries/shared/scoped_queries_tests.dart b/test/unit/dom/queries/shared/scoped_queries_tests.dart index 8bc9005d..1455c0ec 100644 --- a/test/unit/dom/queries/shared/scoped_queries_tests.dart +++ b/test/unit/dom/queries/shared/scoped_queries_tests.dart @@ -45,7 +45,7 @@ void hasQueriesScopedTo( getWrapper, {bool isGloballyScoped = true}) { group('$scopeName:', () { - String expectedPrettyDom; + late String expectedPrettyDom; initConfigForInternalTesting(); @@ -83,7 +83,7 @@ void hasQueriesScopedTo( expectedPrettyDom = prettyDOM(getQueryContainer(tempRenderResult)); tempRenderResult.unmount(); - tempRenderResult.container?.remove(); + tempRenderResult.container.remove(); } // Only render this after the async snapshot is taken to ensure diff --git a/test/unit/dom/queries/shared/text_match_type_parsing_tests.dart b/test/unit/dom/queries/shared/text_match_type_parsing_tests.dart index 486dc34a..e4d0dde7 100644 --- a/test/unit/dom/queries/shared/text_match_type_parsing_tests.dart +++ b/test/unit/dom/queries/shared/text_match_type_parsing_tests.dart @@ -102,7 +102,7 @@ void testTextMatchTypes( // When running only a single test, if the query is an async one, // RenderResult.container will not be accurate when called - so `expectedPrettyDom` will be null. final expectedPrettyDom = getExpectedPrettyDom(); - final stringPrettyDomMatcher = expectedPrettyDom != null ? contains(expectedPrettyDom) : null; + final stringPrettyDomMatcher = contains(expectedPrettyDom); return toThrowErrorMatchingInlineSnapshot( containsMatcher, stringPrettyDomMatcher, isNot(contains('return dart.dcall'))); } @@ -205,7 +205,7 @@ void testTextMatchTypes( }) { late String queryFnString; Function queryFn; - Node container; + Node? container; late dynamic Function() getQueryResult; void sharedSetup({bool renderMultipleElsMatchingQuery = false}) { diff --git a/test/unit/dom/top_level_queries_test.dart b/test/unit/dom/top_level_queries_test.dart index e8f1babc..e82452dd 100644 --- a/test/unit/dom/top_level_queries_test.dart +++ b/test/unit/dom/top_level_queries_test.dart @@ -82,8 +82,8 @@ void main() { group('contains queries that can be scoped to the specified container', () { const scopeName = 'top level'; - Node container; - String expectedPrettyDom; + late Node container; + late String expectedPrettyDom; Function _renderForQuery( Function query, { @@ -115,7 +115,7 @@ void main() { rtl.render(cloneElement(view.renderedElement, {'delay': Duration.zero}), autoTearDown: false); expectedPrettyDom = rtl.prettyDOM(tempRenderResult.container); tempRenderResult.unmount(); - tempRenderResult.container?.remove(); + tempRenderResult.container.remove(); } return query; diff --git a/test/unit/dom/wait_for_test.dart b/test/unit/dom/wait_for_test.dart index a014db4b..8b470793 100644 --- a/test/unit/dom/wait_for_test.dart +++ b/test/unit/dom/wait_for_test.dart @@ -33,7 +33,7 @@ void main() { initConfigForInternalTesting(); late rtl.RenderResult view; - Element rootElement; + late Element rootElement; group('waitFor()', () { setUp(() { @@ -262,15 +262,6 @@ void main() { ))); }, timeout: asyncQueryTestTimeout); - test('null, throws', () async { - expect( - () => rtl.waitForElementToBeRemoved((() => null) as Node Function(), container: view.container), - throwsA(allOf( - isA(), - hasToStringValue(contains('The callback must return a non-null Element.')), - ))); - }, timeout: asyncQueryTestTimeout); - test('an element that is never removed, throws with default timeout value', () async { expect( () => rtl.waitForElementToBeRemoved(() => elementThatWontBeRemoved, container: view.container), @@ -436,15 +427,6 @@ void main() { ))); }, timeout: asyncQueryTestTimeout); - test('null, throws', () async { - expect( - () => rtl.waitForElementsToBeRemoved((() => null) as List Function(), container: view.container), - throwsA(allOf( - isA(), - hasToStringValue(contains('The callback must return one or more non-null Elements.')), - ))); - }, timeout: asyncQueryTestTimeout); - test('an empty list, throws', () async { expect( () => rtl.waitForElementsToBeRemoved(() => [], container: view.container), diff --git a/test/unit/react/render_test.dart b/test/unit/react/render_test.dart index c3872ad7..c20a599e 100644 --- a/test/unit/react/render_test.dart +++ b/test/unit/react/render_test.dart @@ -18,7 +18,6 @@ import 'dart:html'; import 'package:react/react.dart' as react; import 'package:react/react_client/react_interop.dart'; import 'package:react/react_dom.dart' as react_dom; -import 'package:react/react_client.dart' show ReactElement; import 'package:react_testing_library/matchers.dart'; import 'package:react_testing_library/react_testing_library.dart' as rtl; import 'package:test/test.dart'; @@ -186,7 +185,7 @@ void main() { group('prints react warnings', () { test('for custom component', () { final printCalls = recordPrintCalls( - () => rtl.render(testComponent({'name': '123456789012345678901'}) as ReactElement), + () => rtl.render(testComponent({'name': '123456789012345678901'})), ); if (runtimeSupportsPropTypeWarnings()) { expect( @@ -207,7 +206,7 @@ void main() { }); test('scopes queries to the body by default', () { - final view = rtl.render(PortalComponent({}) as ReactElement); + final view = rtl.render(PortalComponent({})); expect(view.getByRole('tooltip'), isInTheDocument); @@ -233,7 +232,7 @@ void main() { expect(() { spyOnPrintCalls(() { - rtl.render(TestFailComponent({}) as ReactElement); + rtl.render(TestFailComponent({})); }, onPrint: printCalls.add); }, throwsA(isA())); diff --git a/test/unit/user_event/paste_test.dart b/test/unit/user_event/paste_test.dart index 926362b2..6ded2f98 100644 --- a/test/unit/user_event/paste_test.dart +++ b/test/unit/user_event/paste_test.dart @@ -28,7 +28,7 @@ void main() { group('UserEvent.paste', () { late List calls; rtl.RenderResult view; - InputElement input; + late InputElement input; setUp(() { calls = []; diff --git a/test/unit/user_event/tab_test.dart b/test/unit/user_event/tab_test.dart index 2aeff9d9..9cc275cb 100644 --- a/test/unit/user_event/tab_test.dart +++ b/test/unit/user_event/tab_test.dart @@ -28,7 +28,7 @@ import '../util/over_react_stubs.dart'; void main() { group('UserEvent.tab events:', () { late rtl.RenderResult view; - List inputs; + late List inputs; group('', () { setUp(() { diff --git a/test/unit/user_event/type_test.dart b/test/unit/user_event/type_test.dart index e047d24d..a2531923 100644 --- a/test/unit/user_event/type_test.dart +++ b/test/unit/user_event/type_test.dart @@ -60,10 +60,10 @@ void main() { } void _typeTestHelper({bool hasDelay = false, bool isTextArea = false}) { - int clickEventCount; - Element element; + late int clickEventCount; + late Element element; late List keyUpCalls; - rtl.RenderResult view; + late rtl.RenderResult view; void _verifyTypeEvent({ bool skipClick = false, diff --git a/test/unit/util/init.dart b/test/unit/util/init.dart index 605631ac..b7292587 100644 --- a/test/unit/util/init.dart +++ b/test/unit/util/init.dart @@ -22,7 +22,7 @@ import 'package:test/test.dart'; import 'constants.dart'; void initConfigForInternalTesting([Function()? additionalSetup]) { - JsConfig initialConfig; + late JsConfig initialConfig; setUpAll(() { initialConfig = rtl.getConfig(); diff --git a/test/unit/util/matchers.dart b/test/unit/util/matchers.dart index a6f7bdcd..b5af8377 100644 --- a/test/unit/util/matchers.dart +++ b/test/unit/util/matchers.dart @@ -39,6 +39,7 @@ Matcher toThrowErrorMatchingInlineSnapshot( final errorNameMatcher = hasToStringValue(contains('TestingLibraryElementError')); final snapshotMatcher = hasToStringValue(stringSnapshotMatcher); final prettyDomMatcher = + // ignore: unnecessary_null_comparison stringPrettyDomMatcher != null ? hasToStringValue(stringPrettyDomMatcher) : hasToStringValue(endsWith('')); return throwsA(allOf(isA(), errorNameMatcher, snapshotMatcher, prettyDomMatcher, diff --git a/test/unit/util/over_react_stubs.dart b/test/unit/util/over_react_stubs.dart index 94b58b45..8798437c 100644 --- a/test/unit/util/over_react_stubs.dart +++ b/test/unit/util/over_react_stubs.dart @@ -44,6 +44,7 @@ external ReactElement _cloneElement(element, [props, children]); /// > There is no special behavior for merging any props (unlike cloneWithProps). /// > See the [v0.13 RC2 blog post](https://facebook.github.io/react/blog/2015/03/03/react-v0.13-rc2.html) for additional details. ReactElement cloneElement(ReactElement element, [Map? props, Iterable? children]) { + // ignore: unnecessary_null_comparison if (element == null) throw ArgumentError.notNull('element'); final propsChangeset = preparePropsChangeset(element, props, children); diff --git a/test/unit/util/prints_and_logs_recording.dart b/test/unit/util/prints_and_logs_recording.dart index 87ea08d0..bca3265f 100644 --- a/test/unit/util/prints_and_logs_recording.dart +++ b/test/unit/util/prints_and_logs_recording.dart @@ -15,7 +15,6 @@ import 'dart:async'; -import 'package:meta/meta.dart'; import 'package:react_testing_library/src/util/console_log_utils.dart'; /// Runs a provided [callback] and returns the print statements captured during the runtime diff --git a/test/unit/util/rendering.dart b/test/unit/util/rendering.dart index dde77f20..4790c47f 100644 --- a/test/unit/util/rendering.dart +++ b/test/unit/util/rendering.dart @@ -28,7 +28,6 @@ const validRoleNotInDom = 'tablist'; ReactElement elementsForQuerying(String uniqueName, {bool? renderMultipleElsMatchingQuery}) { ReactElement renderEls(String _uniqueName) { - _uniqueName ??= uniqueName; return react.div( { defaultTestIdKey: _uniqueName, From a6f489af968b7b8ed8fdbd512a67d18de63e086f Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Fri, 16 Jun 2023 13:49:17 -0500 Subject: [PATCH 05/31] Indent matrix key --- .github/workflows/dart_ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dart_ci.yml b/.github/workflows/dart_ci.yml index 260af3a0..3e502f70 100644 --- a/.github/workflows/dart_ci.yml +++ b/.github/workflows/dart_ci.yml @@ -52,8 +52,8 @@ jobs: runs-on: ubuntu-latest strategy: fail-fast: false - matrix: - sdk: [ 2.13.4 ] + matrix: + sdk: [ 2.13.4 ] steps: - uses: actions/checkout@v2 - uses: dart-lang/setup-dart@v1 @@ -85,4 +85,4 @@ jobs: pub run build_runner test -r -- -P concurrent-tests pub run build_runner test -r -- -P non-concurrent-tests timeout-minutes: 10 - if: ${{ always() && steps.install.outcome == 'success' }} \ No newline at end of file + if: ${{ always() && steps.install.outcome == 'success' }} From 1fb1844fd449a3775c6fec832bb7dd8dbb1090b1 Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Fri, 16 Jun 2023 13:54:09 -0500 Subject: [PATCH 06/31] Update dep override --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 1e7bfa1e..5b70a413 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -25,5 +25,5 @@ dev_dependencies: dependency_overrides: react: git: - url: git@github.com:Workiva/react-dart.git + url: https://github.com/Workiva/react-dart ref: null-safety-manual From ffb26fbf62c66745666c58dcf89f5eef8ab7213d Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Wed, 21 Jun 2023 10:44:37 -0700 Subject: [PATCH 07/31] Fix query tests --- lib/src/dom/config/configure.dart | 6 +++--- lib/src/dom/queries/by_alt_text.dart | 6 +++--- lib/src/dom/queries/by_display_value.dart | 11 ++++++----- lib/src/dom/queries/by_label_text.dart | 6 +++--- lib/src/dom/queries/by_placeholder_text.dart | 6 +++--- lib/src/dom/queries/by_role.dart | 6 +++--- lib/src/dom/queries/by_testid.dart | 10 +++++----- lib/src/dom/queries/by_text.dart | 6 +++--- lib/src/dom/queries/by_title.dart | 6 +++--- lib/src/dom/top_level_queries.dart | 16 ++++++++-------- lib/src/matchers/jest_dom/has_styles.dart | 2 +- lib/src/util/error_message_utils.dart | 4 ++-- 12 files changed, 43 insertions(+), 42 deletions(-) diff --git a/lib/src/dom/config/configure.dart b/lib/src/dom/config/configure.dart index 4d51267f..3a8ff625 100644 --- a/lib/src/dom/config/configure.dart +++ b/lib/src/dom/config/configure.dart @@ -34,10 +34,10 @@ void configure({ bool? defaultHidden, bool? showOriginalStackTrace, bool? throwSuggestions, - TestingLibraryElementError Function(Object message, Element container)? getElementError, + TestingLibraryElementError Function(Object? message, Element container)? getElementError, }) { - JsError _getJsGetElementError(Object message, Element container) { - final dartError = allowInterop(getElementError!)(message, container); + JsError _getJsGetElementError(Object? message, Element container) { + final dartError = allowInterop(getElementError!)(message ?? '', container); return buildJsGetElementError(dartError.message, container); } diff --git a/lib/src/dom/queries/by_alt_text.dart b/lib/src/dom/queries/by_alt_text.dart index 6945cde1..4903645e 100644 --- a/lib/src/dom/queries/by_alt_text.dart +++ b/lib/src/dom/queries/by_alt_text.dart @@ -158,7 +158,7 @@ mixin ByAltTextQueries on IQueries { /// {@macro TextMatchArgDescription} /// {@macro MatcherOptionsExactArgDescription} /// {@macro MatcherOptionsNormalizerArgDescription} - E queryByAltText( + E? queryByAltText( /*TextMatch*/ dynamic text, { bool exact = true, NormalizerFn Function([NormalizerOptions?])? normalizer, @@ -167,7 +167,7 @@ mixin ByAltTextQueries on IQueries { getContainerForScope(), TextMatch.toJs(text), buildMatcherOptions(exact: exact, normalizer: normalizer), - ) as E; + ) as E?; /// Returns a list of [ImageElement]s, [InputElement]s and/or [AreaElement]s with the given [text] as the value of /// the `alt` attribute, defaulting to an [exact] match. @@ -329,7 +329,7 @@ external List< /*Element*/ dynamic> _jsGetAllByAltText( ]); @JS('rtl.queryByAltText') -external Element _jsQueryByAltText( +external Element? _jsQueryByAltText( Node? container, /*TextMatch*/ dynamic text, [ MatcherOptions? options, diff --git a/lib/src/dom/queries/by_display_value.dart b/lib/src/dom/queries/by_display_value.dart index 6f8828b2..4d1275a4 100644 --- a/lib/src/dom/queries/by_display_value.dart +++ b/lib/src/dom/queries/by_display_value.dart @@ -184,16 +184,17 @@ mixin ByDisplayValueQueries on IQueries { /// {@macro TextMatchArgDescription} /// {@macro MatcherOptionsExactArgDescription} /// {@macro MatcherOptionsNormalizerArgDescription} - E queryByDisplayValue( + E? queryByDisplayValue( /*TextMatch*/ dynamic value, { bool exact = true, NormalizerFn Function([NormalizerOptions?])? normalizer, - }) => - _jsQueryByDisplayValue( + }) { + return _jsQueryByDisplayValue( getContainerForScope(), TextMatch.toJs(value), buildMatcherOptions(exact: exact, normalizer: normalizer), - ) as E; + ) as E?; + } /// Returns a list of [InputElement]s, [TextAreaElement]s or [SelectElement]s that have the matching [value] displayed, /// defaulting to an [exact] match. @@ -353,7 +354,7 @@ external List< /*Element*/ dynamic> _jsGetAllByDisplayValue( ]); @JS('rtl.queryByDisplayValue') -external Element _jsQueryByDisplayValue( +external Element? _jsQueryByDisplayValue( Node? container, /*TextMatch*/ dynamic value, [ MatcherOptions? options, diff --git a/lib/src/dom/queries/by_label_text.dart b/lib/src/dom/queries/by_label_text.dart index 07a23446..765d418b 100644 --- a/lib/src/dom/queries/by_label_text.dart +++ b/lib/src/dom/queries/by_label_text.dart @@ -176,7 +176,7 @@ mixin ByLabelTextQueries on IQueries { /// {@macro MatcherOptionsExactArgDescription} /// {@macro MatcherOptionsNormalizerArgDescription} /// {@macro MatcherOptionsSelectorArgDescription} - E queryByLabelText( + E? queryByLabelText( /*TextMatch*/ dynamic text, { bool exact = true, NormalizerFn Function([NormalizerOptions?])? normalizer, @@ -186,7 +186,7 @@ mixin ByLabelTextQueries on IQueries { getContainerForScope(), TextMatch.toJs(text), buildMatcherOptions(exact: exact, normalizer: normalizer, selector: selector), - ) as E; + ) as E?; /// Returns a list of elements that are associated with a [LabelElement] with the given [text], /// defaulting to an [exact] match. @@ -348,7 +348,7 @@ external List< /*Element*/ dynamic> _jsGetAllByLabelText( ]); @JS('rtl.queryByLabelText') -external Element _jsQueryByLabelText( +external Element? _jsQueryByLabelText( Node? container, /*TextMatch*/ dynamic text, [ MatcherOptions? options, diff --git a/lib/src/dom/queries/by_placeholder_text.dart b/lib/src/dom/queries/by_placeholder_text.dart index 08d7590c..14f7eddb 100644 --- a/lib/src/dom/queries/by_placeholder_text.dart +++ b/lib/src/dom/queries/by_placeholder_text.dart @@ -154,7 +154,7 @@ mixin ByPlaceholderTextQueries on IQueries { /// {@macro TextMatchArgDescription} /// {@macro MatcherOptionsExactArgDescription} /// {@macro MatcherOptionsNormalizerArgDescription} - E queryByPlaceholderText( + E? queryByPlaceholderText( /*TextMatch*/ dynamic text, { bool exact = true, NormalizerFn Function([NormalizerOptions?])? normalizer, @@ -163,7 +163,7 @@ mixin ByPlaceholderTextQueries on IQueries { getContainerForScope(), TextMatch.toJs(text), buildMatcherOptions(exact: exact, normalizer: normalizer), - ) as E; + ) as E?; /// Returns a list of elements with the given [text] as the value of the `placeholder` attribute, /// defaulting to an [exact] match. @@ -323,7 +323,7 @@ external List< /*Element*/ dynamic> _jsGetAllByPlaceholderText( ]); @JS('rtl.queryByPlaceholderText') -external Element _jsQueryByPlaceholderText( +external Element? _jsQueryByPlaceholderText( Node? container, /*TextMatch*/ dynamic text, [ MatcherOptions? options, diff --git a/lib/src/dom/queries/by_role.dart b/lib/src/dom/queries/by_role.dart index e9e2f3e5..a9e21fb5 100644 --- a/lib/src/dom/queries/by_role.dart +++ b/lib/src/dom/queries/by_role.dart @@ -238,7 +238,7 @@ mixin ByRoleQueries on IQueries { /// {@macro byRoleOptionsExpanded} /// {@macro byRoleOptionsQueryFallbacks} /// {@macro byRoleOptionsLevel} - E queryByRole( + E? queryByRole( /*TextMatch*/ dynamic role, { bool exact = true, NormalizerFn Function([NormalizerOptions?])? normalizer, @@ -266,7 +266,7 @@ mixin ByRoleQueries on IQueries { queryFallbacks: queryFallbacks, level: level, ), - ) as E; + ) as E?; /// Returns a list of elements with the given [role] value, defaulting to an [exact] match. /// @@ -497,7 +497,7 @@ external List< /*Element*/ dynamic> _jsGetAllByRole( ]); @JS('rtl.queryByRole') -external Element _jsQueryByRole( +external Element? _jsQueryByRole( Node? container, /*TextMatch*/ dynamic role, [ ByRoleOptions? options, diff --git a/lib/src/dom/queries/by_testid.dart b/lib/src/dom/queries/by_testid.dart index b5fff782..fa773b10 100644 --- a/lib/src/dom/queries/by_testid.dart +++ b/lib/src/dom/queries/by_testid.dart @@ -40,7 +40,7 @@ import 'package:react_testing_library/src/dom/async/wait_for.dart'; import 'package:react_testing_library/src/dom/matches/types.dart'; import 'package:react_testing_library/src/dom/queries/interface.dart'; import 'package:react_testing_library/src/util/error_message_utils.dart' - show TestingLibraryElementError, withErrorInterop; + show TestingLibraryElementError, withErrorInterop, withErrorInterop2; /// PRIVATE. Do not export from this library. /// @@ -206,20 +206,20 @@ mixin ByTestIdQueries on IQueries { /// {@macro TextMatchArgDescription} /// {@macro MatcherOptionsExactArgDescription} /// {@macro MatcherOptionsNormalizerArgDescription} - E queryByTestId( + E? queryByTestId( /*TextMatch*/ dynamic testId, { bool exact = true, NormalizerFn Function([NormalizerOptions?])? normalizer, }) { // For strings, we need to jump through a few more hoops to ensure that we support matching a single // test id value on an element that may have more than one. - E jsQuery(dynamic testIdTextMatchValue) { + E? jsQuery(dynamic testIdTextMatchValue) { return withErrorInterop( () => _jsQueryByTestId( getContainerForScope(), testIdTextMatchValue, buildMatcherOptions(exact: exact, normalizer: normalizer), - ) as E, + ) as E?, ); } @@ -423,7 +423,7 @@ external List< /*Element*/ dynamic> _jsGetAllByTestId( ]); @JS('rtl.queryByTestId') -external Element _jsQueryByTestId( +external Element? _jsQueryByTestId( Node? container, /*TextMatch*/ dynamic testId, [ MatcherOptions? options, diff --git a/lib/src/dom/queries/by_text.dart b/lib/src/dom/queries/by_text.dart index 239d597b..7ce0a70a 100644 --- a/lib/src/dom/queries/by_text.dart +++ b/lib/src/dom/queries/by_text.dart @@ -166,7 +166,7 @@ mixin ByTextQueries on IQueries { /// {@macro MatcherOptionsNormalizerArgDescription} /// {@macro MatcherOptionsSelectorArgDescription} /// {@macro MatcherOptionsIgnoreArgDescription} - E queryByText( + E? queryByText( /*TextMatch*/ dynamic text, { bool exact = true, NormalizerFn Function([NormalizerOptions?])? normalizer, @@ -177,7 +177,7 @@ mixin ByTextQueries on IQueries { getContainerForScope(), TextMatch.toJs(text), buildMatcherOptions(exact: exact, normalizer: normalizer, selector: selector, ignore: ignore), - ) as E; + ) as E?; /// Returns a list of elements with the given [text] content, defaulting to an [exact] match. /// @@ -352,7 +352,7 @@ external List< /*Element*/ dynamic> _jsGetAllByText( ]); @JS('rtl.queryByText') -external Element _jsQueryByText( +external Element? _jsQueryByText( Node? container, /*TextMatch*/ dynamic text, [ MatcherOptions? options, diff --git a/lib/src/dom/queries/by_title.dart b/lib/src/dom/queries/by_title.dart index 0e38de15..969f883c 100644 --- a/lib/src/dom/queries/by_title.dart +++ b/lib/src/dom/queries/by_title.dart @@ -163,7 +163,7 @@ mixin ByTitleQueries on IQueries { /// {@macro TextMatchArgDescription} /// {@macro MatcherOptionsExactArgDescription} /// {@macro MatcherOptionsNormalizerArgDescription} - E queryByTitle( + E? queryByTitle( /*TextMatch*/ dynamic title, { bool exact = true, NormalizerFn Function([NormalizerOptions?])? normalizer, @@ -172,7 +172,7 @@ mixin ByTitleQueries on IQueries { getContainerForScope(), TextMatch.toJs(title), buildMatcherOptions(exact: exact, normalizer: normalizer), - ) as E; + ) as E?; /// Returns a list of elements with the given [title] as the value of the `title` attribute, /// defaulting to an [exact] match. @@ -332,7 +332,7 @@ external List< /*Element*/ dynamic> _jsGetAllByTitle( ]); @JS('rtl.queryByTitle') -external Element _jsQueryByTitle( +external Element? _jsQueryByTitle( Node? container, /*TextMatch*/ dynamic title, [ MatcherOptions? options, diff --git a/lib/src/dom/top_level_queries.dart b/lib/src/dom/top_level_queries.dart index 36b312c1..2deaafcb 100644 --- a/lib/src/dom/top_level_queries.dart +++ b/lib/src/dom/top_level_queries.dart @@ -113,7 +113,7 @@ List getAllByAltText( /// /// {@category Queries} /// {@category ByAltText} -E queryByAltText( +E? queryByAltText( Node container, /*TextMatch*/ dynamic text, { bool exact = true, @@ -351,7 +351,7 @@ List getAllByDisplayValue( /// /// {@category Queries} /// {@category ByDisplayValue} -E queryByDisplayValue( +E? queryByDisplayValue( Node container, /*TextMatch*/ dynamic value, { bool exact = true, @@ -586,7 +586,7 @@ List getAllByLabelText( /// /// {@category Queries} /// {@category ByLabelText} -E queryByLabelText( +E? queryByLabelText( Node container, /*TextMatch*/ dynamic text, { bool exact = true, @@ -825,7 +825,7 @@ List getAllByPlaceholderText( /// /// {@category Queries} /// {@category ByPlaceholderText} -E queryByPlaceholderText( +E? queryByPlaceholderText( Node container, /*TextMatch*/ dynamic text, { bool exact = true, @@ -1112,7 +1112,7 @@ List getAllByRole( /// /// {@category Queries} /// {@category ByRole} -E queryByRole( +E? queryByRole( Node container, /*TextMatch*/ dynamic role, { bool exact = true, @@ -1436,7 +1436,7 @@ List getAllByTestId( /// /// {@category Queries} /// {@category ByTestId} -E queryByTestId( +E? queryByTestId( Node container, /*TextMatch*/ dynamic testId, { bool exact = true, @@ -1679,7 +1679,7 @@ List getAllByText( /// /// {@category Queries} /// {@category ByText} -E queryByText( +E? queryByText( Node container, /*TextMatch*/ dynamic text, { bool exact = true, @@ -1932,7 +1932,7 @@ List getAllByTitle( /// /// {@category Queries} /// {@category ByTitle} -E queryByTitle( +E? queryByTitle( Node container, /*TextMatch*/ dynamic title, { bool exact = true, diff --git a/lib/src/matchers/jest_dom/has_styles.dart b/lib/src/matchers/jest_dom/has_styles.dart index 6fab1483..aee7f2a1 100644 --- a/lib/src/matchers/jest_dom/has_styles.dart +++ b/lib/src/matchers/jest_dom/has_styles.dart @@ -134,7 +134,7 @@ class _HasStyles extends CustomMatcher { }); if (normalizedValue is String) { - normalizedValue = num.tryParse(normalizedValue) as String? ?? normalizedValue; + normalizedValue = num.tryParse(normalizedValue) ?? normalizedValue; } return normalizedValue; diff --git a/lib/src/util/error_message_utils.dart b/lib/src/util/error_message_utils.dart index 72284b99..6e2620e1 100644 --- a/lib/src/util/error_message_utils.dart +++ b/lib/src/util/error_message_utils.dart @@ -27,9 +27,9 @@ import 'package:react_testing_library/src/dom/config/configure.dart' show config void setEphemeralElementErrorMessage( Object Function(Object originalMessage, Element container) customErrorMessageBuilder, {StackTrace? jsStackTrace}) { - TestingLibraryElementError buildCustomDartGetElementError(Object originalMessage, Element container) { + TestingLibraryElementError buildCustomDartGetElementError(Object? originalMessage, Element container) { return TestingLibraryElementError.fromJs( - buildJsGetElementError(customErrorMessageBuilder(originalMessage, container), container), jsStackTrace); + buildJsGetElementError(customErrorMessageBuilder(originalMessage ?? '', container), container), jsStackTrace); } configure(getElementError: buildCustomDartGetElementError); From 7f7850c43ffe0c2c196eacc94bd4581f281bb3c8 Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Fri, 23 Jun 2023 09:46:52 -0700 Subject: [PATCH 08/31] Fix isDisabled --- lib/src/matchers/jest_dom/is_disabled.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/matchers/jest_dom/is_disabled.dart b/lib/src/matchers/jest_dom/is_disabled.dart index 8d6cfcec..ca39a6ff 100644 --- a/lib/src/matchers/jest_dom/is_disabled.dart +++ b/lib/src/matchers/jest_dom/is_disabled.dart @@ -89,7 +89,7 @@ class _IsDisabled extends Matcher { if (!isElementThatCanBeDisabled(item, matchState)) return false; final formAncestor = (item as Element).closest('form'); if (formAncestor != null && (formAncestor as FormElement).hasAttribute('disabled')) return true; - return (item as ButtonElement).disabled; + return (item as dynamic).disabled as bool; } void setMatchState(dynamic item, Map matchState) { From a7a768934df8c6b69aa29ff7792d2591d4b412db Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Fri, 23 Jun 2023 09:48:57 -0700 Subject: [PATCH 09/31] Format --- lib/dom/accessibility.dart | 1 - lib/dom/async.dart | 1 - lib/dom/configure.dart | 1 - lib/dom/debugging.dart | 1 - lib/dom/events.dart | 1 - lib/dom/queries.dart | 1 - lib/matchers.dart | 1 - lib/react/react.dart | 1 - lib/react_testing_library.dart | 1 - lib/src/dom/accessibility_helpers.dart | 1 - lib/src/dom/async/types.dart | 1 - lib/src/dom/async/wait_for.dart | 1 - lib/src/dom/config/configure.dart | 1 - lib/src/dom/config/types.dart | 1 - lib/src/dom/fire_event.dart | 1 - .../dom/matches/get_default_normalizer.dart | 1 - lib/src/dom/matches/types.dart | 1 - lib/src/dom/pretty_dom.dart | 1 - lib/src/dom/queries/by_alt_text.dart | 1 - lib/src/dom/queries/by_display_value.dart | 9 ++- lib/src/dom/queries/by_label_text.dart | 1 - lib/src/dom/queries/by_placeholder_text.dart | 1 - lib/src/dom/queries/by_role.dart | 1 - lib/src/dom/queries/by_testid.dart | 1 - lib/src/dom/queries/by_text.dart | 1 - lib/src/dom/queries/by_title.dart | 1 - lib/src/dom/queries/interface.dart | 1 - lib/src/dom/scoped_queries.dart | 1 - lib/src/dom/top_level_queries.dart | 1 - lib/src/dom/within.dart | 1 - lib/src/matchers/jest_dom.dart | 1 - .../matchers/jest_dom/contains_element.dart | 1 - .../matchers/jest_dom/css_class_matchers.dart | 1 - lib/src/matchers/jest_dom/has_attribute.dart | 1 - .../matchers/jest_dom/has_description.dart | 1 - .../matchers/jest_dom/has_form_values.dart | 1 - lib/src/matchers/jest_dom/has_styles.dart | 1 - .../matchers/jest_dom/has_text_content.dart | 1 - lib/src/matchers/jest_dom/has_value.dart | 1 - lib/src/matchers/jest_dom/is_checked.dart | 1 - lib/src/matchers/jest_dom/is_disabled.dart | 1 - .../jest_dom/is_empty_dom_element.dart | 1 - lib/src/matchers/jest_dom/is_focused.dart | 1 - .../matchers/jest_dom/is_in_the_document.dart | 1 - .../jest_dom/is_partially_checked.dart | 1 - lib/src/matchers/jest_dom/util/constants.dart | 1 - .../element_text_content_matcher_mixin.dart | 1 - .../matchers/jest_dom/util/get_value_of.dart | 1 - lib/src/react/render/render.dart | 1 - lib/src/react/render/types.dart | 1 - lib/src/user_event/special_chars.dart | 1 - lib/src/user_event/user_event.dart | 3 +- lib/src/util/console_log_formatter.dart | 59 +++++++++---------- lib/src/util/console_log_utils.dart | 1 - lib/src/util/error_message_utils.dart | 1 - lib/src/util/event_handler_error_catcher.dart | 1 - lib/src/util/is_or_contains.dart | 1 - lib/src/util/js_utils.dart | 1 - lib/user_event.dart | 1 - test/unit/console_log_utils_test.dart | 4 +- test/unit/dom/accessibility_helpers_test.dart | 1 - test/unit/dom/configure_test.dart | 1 - test/unit/dom/fire_event_test.dart | 1 - .../dom/matchers/contains_element_test.dart | 1 - .../dom/matchers/css_class_matchers_test.dart | 1 - .../unit/dom/matchers/has_attribute_test.dart | 1 - .../dom/matchers/has_description_test.dart | 1 - .../dom/matchers/has_form_values_test.dart | 1 - test/unit/dom/matchers/has_styles_test.dart | 1 - .../dom/matchers/has_text_content_test.dart | 1 - test/unit/dom/matchers/has_value_test.dart | 1 - test/unit/dom/matchers/is_checked_test.dart | 1 - test/unit/dom/matchers/is_disabled_test.dart | 1 - .../matchers/is_empty_dom_element_test.dart | 1 - test/unit/dom/matchers/is_focused_test.dart | 1 - .../dom/matchers/is_in_the_document_test.dart | 1 - .../matchers/is_partially_checked_test.dart | 1 - test/unit/dom/pretty_dom_test.dart | 1 - test/unit/dom/queries/by_label_text_test.dart | 1 - test/unit/dom/queries/by_role_test.dart | 1 - test/unit/dom/queries/by_testid_test.dart | 1 - test/unit/dom/queries/by_text_test.dart | 1 - .../queries/shared/scoped_queries_tests.dart | 1 - .../shared/text_match_type_parsing_tests.dart | 1 - test/unit/dom/top_level_queries_test.dart | 5 +- test/unit/dom/wait_for_test.dart | 1 - test/unit/dom/within_test.dart | 5 +- test/unit/react/render_test.dart | 6 +- test/unit/user_event/clear_test.dart | 1 - test/unit/user_event/click_test.dart | 1 - test/unit/user_event/hover_test.dart | 1 - test/unit/user_event/paste_test.dart | 1 - test/unit/user_event/select_options_test.dart | 1 - test/unit/user_event/special_chars_test.dart | 1 - test/unit/user_event/tab_test.dart | 1 - test/unit/user_event/type_test.dart | 1 - test/unit/user_event/upload_test.dart | 1 - test/unit/util/constants.dart | 1 - test/unit/util/enums.dart | 1 - test/unit/util/event_handler_error.dart | 1 - test/unit/util/exception.dart | 1 - test/unit/util/init.dart | 1 - test/unit/util/matchers.dart | 3 +- test/unit/util/over_react_stubs.dart | 1 - test/unit/util/prints_and_logs_recording.dart | 1 - test/unit/util/rendering.dart | 1 - test/unit/util/shadow_dom.dart | 1 - test/unit/util/string_trimming.dart | 1 - 108 files changed, 40 insertions(+), 154 deletions(-) diff --git a/lib/dom/accessibility.dart b/lib/dom/accessibility.dart index e46ab8e2..f5f78e33 100644 --- a/lib/dom/accessibility.dart +++ b/lib/dom/accessibility.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/dom/async.dart b/lib/dom/async.dart index f8a09d5f..5a6431cd 100644 --- a/lib/dom/async.dart +++ b/lib/dom/async.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/dom/configure.dart b/lib/dom/configure.dart index ecdb1d5e..d9ec9339 100644 --- a/lib/dom/configure.dart +++ b/lib/dom/configure.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/dom/debugging.dart b/lib/dom/debugging.dart index 64267dfb..532f80d6 100644 --- a/lib/dom/debugging.dart +++ b/lib/dom/debugging.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/dom/events.dart b/lib/dom/events.dart index 7c6791fe..21cfe4d5 100644 --- a/lib/dom/events.dart +++ b/lib/dom/events.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/dom/queries.dart b/lib/dom/queries.dart index 8df6c624..e473112b 100644 --- a/lib/dom/queries.dart +++ b/lib/dom/queries.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/matchers.dart b/lib/matchers.dart index d7c9b61b..2b16b39e 100644 --- a/lib/matchers.dart +++ b/lib/matchers.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/react/react.dart b/lib/react/react.dart index f0025338..f0f920b6 100644 --- a/lib/react/react.dart +++ b/lib/react/react.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/react_testing_library.dart b/lib/react_testing_library.dart index 270abfb8..e92933e4 100644 --- a/lib/react_testing_library.dart +++ b/lib/react_testing_library.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/dom/accessibility_helpers.dart b/lib/src/dom/accessibility_helpers.dart index 3b20ed35..a3fc34d6 100644 --- a/lib/src/dom/accessibility_helpers.dart +++ b/lib/src/dom/accessibility_helpers.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/dom/async/types.dart b/lib/src/dom/async/types.dart index 4391e20a..4af725b4 100644 --- a/lib/src/dom/async/types.dart +++ b/lib/src/dom/async/types.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/dom/async/wait_for.dart b/lib/src/dom/async/wait_for.dart index 465ef0ae..cb4f8bef 100644 --- a/lib/src/dom/async/wait_for.dart +++ b/lib/src/dom/async/wait_for.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/dom/config/configure.dart b/lib/src/dom/config/configure.dart index 3a8ff625..6c21207b 100644 --- a/lib/src/dom/config/configure.dart +++ b/lib/src/dom/config/configure.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/dom/config/types.dart b/lib/src/dom/config/types.dart index 00b2b3b5..6c93b187 100644 --- a/lib/src/dom/config/types.dart +++ b/lib/src/dom/config/types.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/dom/fire_event.dart b/lib/src/dom/fire_event.dart index 57fff9d0..5045773c 100644 --- a/lib/src/dom/fire_event.dart +++ b/lib/src/dom/fire_event.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/dom/matches/get_default_normalizer.dart b/lib/src/dom/matches/get_default_normalizer.dart index edde3562..86d53f15 100644 --- a/lib/src/dom/matches/get_default_normalizer.dart +++ b/lib/src/dom/matches/get_default_normalizer.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/dom/matches/types.dart b/lib/src/dom/matches/types.dart index 48954bb2..ebde427f 100644 --- a/lib/src/dom/matches/types.dart +++ b/lib/src/dom/matches/types.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/dom/pretty_dom.dart b/lib/src/dom/pretty_dom.dart index a0409e8b..16264c78 100644 --- a/lib/src/dom/pretty_dom.dart +++ b/lib/src/dom/pretty_dom.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/dom/queries/by_alt_text.dart b/lib/src/dom/queries/by_alt_text.dart index 4903645e..d872b02a 100644 --- a/lib/src/dom/queries/by_alt_text.dart +++ b/lib/src/dom/queries/by_alt_text.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/dom/queries/by_display_value.dart b/lib/src/dom/queries/by_display_value.dart index 4d1275a4..ab65721c 100644 --- a/lib/src/dom/queries/by_display_value.dart +++ b/lib/src/dom/queries/by_display_value.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -190,10 +189,10 @@ mixin ByDisplayValueQueries on IQueries { NormalizerFn Function([NormalizerOptions?])? normalizer, }) { return _jsQueryByDisplayValue( - getContainerForScope(), - TextMatch.toJs(value), - buildMatcherOptions(exact: exact, normalizer: normalizer), - ) as E?; + getContainerForScope(), + TextMatch.toJs(value), + buildMatcherOptions(exact: exact, normalizer: normalizer), + ) as E?; } /// Returns a list of [InputElement]s, [TextAreaElement]s or [SelectElement]s that have the matching [value] displayed, diff --git a/lib/src/dom/queries/by_label_text.dart b/lib/src/dom/queries/by_label_text.dart index 765d418b..34b76582 100644 --- a/lib/src/dom/queries/by_label_text.dart +++ b/lib/src/dom/queries/by_label_text.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/dom/queries/by_placeholder_text.dart b/lib/src/dom/queries/by_placeholder_text.dart index 14f7eddb..33fe8f0d 100644 --- a/lib/src/dom/queries/by_placeholder_text.dart +++ b/lib/src/dom/queries/by_placeholder_text.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/dom/queries/by_role.dart b/lib/src/dom/queries/by_role.dart index a9e21fb5..deb0f226 100644 --- a/lib/src/dom/queries/by_role.dart +++ b/lib/src/dom/queries/by_role.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/dom/queries/by_testid.dart b/lib/src/dom/queries/by_testid.dart index fa773b10..03799d5a 100644 --- a/lib/src/dom/queries/by_testid.dart +++ b/lib/src/dom/queries/by_testid.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/dom/queries/by_text.dart b/lib/src/dom/queries/by_text.dart index 7ce0a70a..008a7416 100644 --- a/lib/src/dom/queries/by_text.dart +++ b/lib/src/dom/queries/by_text.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/dom/queries/by_title.dart b/lib/src/dom/queries/by_title.dart index 969f883c..0538bb2c 100644 --- a/lib/src/dom/queries/by_title.dart +++ b/lib/src/dom/queries/by_title.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/dom/queries/interface.dart b/lib/src/dom/queries/interface.dart index bc5d9c21..28815647 100644 --- a/lib/src/dom/queries/interface.dart +++ b/lib/src/dom/queries/interface.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/dom/scoped_queries.dart b/lib/src/dom/scoped_queries.dart index 9fa68959..fb477a06 100644 --- a/lib/src/dom/scoped_queries.dart +++ b/lib/src/dom/scoped_queries.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/dom/top_level_queries.dart b/lib/src/dom/top_level_queries.dart index 2deaafcb..e51b558b 100644 --- a/lib/src/dom/top_level_queries.dart +++ b/lib/src/dom/top_level_queries.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/dom/within.dart b/lib/src/dom/within.dart index e5bc7e8b..0a71df45 100644 --- a/lib/src/dom/within.dart +++ b/lib/src/dom/within.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/matchers/jest_dom.dart b/lib/src/matchers/jest_dom.dart index 63ed80ef..d703c979 100644 --- a/lib/src/matchers/jest_dom.dart +++ b/lib/src/matchers/jest_dom.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/matchers/jest_dom/contains_element.dart b/lib/src/matchers/jest_dom/contains_element.dart index 898023fd..07135250 100644 --- a/lib/src/matchers/jest_dom/contains_element.dart +++ b/lib/src/matchers/jest_dom/contains_element.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/matchers/jest_dom/css_class_matchers.dart b/lib/src/matchers/jest_dom/css_class_matchers.dart index e81a375e..4c8e2c1b 100644 --- a/lib/src/matchers/jest_dom/css_class_matchers.dart +++ b/lib/src/matchers/jest_dom/css_class_matchers.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/matchers/jest_dom/has_attribute.dart b/lib/src/matchers/jest_dom/has_attribute.dart index 3ef8f102..ab7d1e35 100644 --- a/lib/src/matchers/jest_dom/has_attribute.dart +++ b/lib/src/matchers/jest_dom/has_attribute.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/matchers/jest_dom/has_description.dart b/lib/src/matchers/jest_dom/has_description.dart index 6a98883a..8402f698 100644 --- a/lib/src/matchers/jest_dom/has_description.dart +++ b/lib/src/matchers/jest_dom/has_description.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/matchers/jest_dom/has_form_values.dart b/lib/src/matchers/jest_dom/has_form_values.dart index 6c26709e..82f18dbb 100644 --- a/lib/src/matchers/jest_dom/has_form_values.dart +++ b/lib/src/matchers/jest_dom/has_form_values.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/matchers/jest_dom/has_styles.dart b/lib/src/matchers/jest_dom/has_styles.dart index aee7f2a1..48e0cfd2 100644 --- a/lib/src/matchers/jest_dom/has_styles.dart +++ b/lib/src/matchers/jest_dom/has_styles.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/matchers/jest_dom/has_text_content.dart b/lib/src/matchers/jest_dom/has_text_content.dart index b69d686b..0bc1ca7d 100644 --- a/lib/src/matchers/jest_dom/has_text_content.dart +++ b/lib/src/matchers/jest_dom/has_text_content.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/matchers/jest_dom/has_value.dart b/lib/src/matchers/jest_dom/has_value.dart index d13cb61c..cdb7b2c1 100644 --- a/lib/src/matchers/jest_dom/has_value.dart +++ b/lib/src/matchers/jest_dom/has_value.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/matchers/jest_dom/is_checked.dart b/lib/src/matchers/jest_dom/is_checked.dart index ff85e564..fc43feb1 100644 --- a/lib/src/matchers/jest_dom/is_checked.dart +++ b/lib/src/matchers/jest_dom/is_checked.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/matchers/jest_dom/is_disabled.dart b/lib/src/matchers/jest_dom/is_disabled.dart index ca39a6ff..570171d1 100644 --- a/lib/src/matchers/jest_dom/is_disabled.dart +++ b/lib/src/matchers/jest_dom/is_disabled.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/matchers/jest_dom/is_empty_dom_element.dart b/lib/src/matchers/jest_dom/is_empty_dom_element.dart index 35007832..27de68aa 100644 --- a/lib/src/matchers/jest_dom/is_empty_dom_element.dart +++ b/lib/src/matchers/jest_dom/is_empty_dom_element.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/matchers/jest_dom/is_focused.dart b/lib/src/matchers/jest_dom/is_focused.dart index 963ff9f4..eeeed24f 100644 --- a/lib/src/matchers/jest_dom/is_focused.dart +++ b/lib/src/matchers/jest_dom/is_focused.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/matchers/jest_dom/is_in_the_document.dart b/lib/src/matchers/jest_dom/is_in_the_document.dart index 0ceafc38..f668dfa5 100644 --- a/lib/src/matchers/jest_dom/is_in_the_document.dart +++ b/lib/src/matchers/jest_dom/is_in_the_document.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/matchers/jest_dom/is_partially_checked.dart b/lib/src/matchers/jest_dom/is_partially_checked.dart index e35313d7..afb495b1 100644 --- a/lib/src/matchers/jest_dom/is_partially_checked.dart +++ b/lib/src/matchers/jest_dom/is_partially_checked.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/matchers/jest_dom/util/constants.dart b/lib/src/matchers/jest_dom/util/constants.dart index 8a112952..a1881ff3 100644 --- a/lib/src/matchers/jest_dom/util/constants.dart +++ b/lib/src/matchers/jest_dom/util/constants.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/matchers/jest_dom/util/element_text_content_matcher_mixin.dart b/lib/src/matchers/jest_dom/util/element_text_content_matcher_mixin.dart index af4fd0a7..0e4fbab0 100644 --- a/lib/src/matchers/jest_dom/util/element_text_content_matcher_mixin.dart +++ b/lib/src/matchers/jest_dom/util/element_text_content_matcher_mixin.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/matchers/jest_dom/util/get_value_of.dart b/lib/src/matchers/jest_dom/util/get_value_of.dart index dcd0e9eb..62222d49 100644 --- a/lib/src/matchers/jest_dom/util/get_value_of.dart +++ b/lib/src/matchers/jest_dom/util/get_value_of.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/react/render/render.dart b/lib/src/react/render/render.dart index 03d963fa..676c568f 100644 --- a/lib/src/react/render/render.dart +++ b/lib/src/react/render/render.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/react/render/types.dart b/lib/src/react/render/types.dart index 052fedef..be4d5365 100644 --- a/lib/src/react/render/types.dart +++ b/lib/src/react/render/types.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/user_event/special_chars.dart b/lib/src/user_event/special_chars.dart index ab2bcb95..1e3d5d52 100644 --- a/lib/src/user_event/special_chars.dart +++ b/lib/src/user_event/special_chars.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/user_event/user_event.dart b/lib/src/user_event/user_event.dart index 44039b22..e24003ce 100644 --- a/lib/src/user_event/user_event.dart +++ b/lib/src/user_event/user_event.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -1431,7 +1430,7 @@ List _unjsifyFileList(List? fileList) { final convertedFiles = []; for (var i = 0; i < (jsFileList['length'] as int); i++) { final file = jsFileList['item'](i); - if(file is File) { + if (file is File) { convertedFiles.add(file); } } diff --git a/lib/src/util/console_log_formatter.dart b/lib/src/util/console_log_formatter.dart index ba2eea50..e97292f6 100644 --- a/lib/src/util/console_log_formatter.dart +++ b/lib/src/util/console_log_formatter.dart @@ -1,4 +1,3 @@ - // This code was adapted to Dart from // https://github.com/nodejs/node-v0.x-archive/blob/master/lib/util.js // @@ -48,36 +47,36 @@ String format(dynamic f, List arguments) { } var str = ''; - var i = 0; - final len = arguments.length; - str += f.replaceAllMapped(_formatRegExp, (m) { - final x = m[0]; - if (x == '%%') return '%'; - if (i >= len) return x!; - switch (x) { - case '%s': - return arguments[i++].toString(); - case '%i': - case '%d': - case '%f': - return num.tryParse(arguments[i++].toString()).toString(); - case '%o': - case '%O': - case '%j': - try { - final argToStringify = arguments[i++]; - return _jsonStringify(argToStringify); - } catch (_) { - return '[Circular]'; - } - default: - return x!; - } - }); - - if (i < len) { - str += ' ${arguments.skip(i).join(' ')}'; + var i = 0; + final len = arguments.length; + str += f.replaceAllMapped(_formatRegExp, (m) { + final x = m[0]; + if (x == '%%') return '%'; + if (i >= len) return x!; + switch (x) { + case '%s': + return arguments[i++].toString(); + case '%i': + case '%d': + case '%f': + return num.tryParse(arguments[i++].toString()).toString(); + case '%o': + case '%O': + case '%j': + try { + final argToStringify = arguments[i++]; + return _jsonStringify(argToStringify); + } catch (_) { + return '[Circular]'; + } + default: + return x!; } + }); + + if (i < len) { + str += ' ${arguments.skip(i).join(' ')}'; + } return str; } diff --git a/lib/src/util/console_log_utils.dart b/lib/src/util/console_log_utils.dart index 215228e8..62b82b1e 100644 --- a/lib/src/util/console_log_utils.dart +++ b/lib/src/util/console_log_utils.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/util/error_message_utils.dart b/lib/src/util/error_message_utils.dart index 6e2620e1..cc0c93e8 100644 --- a/lib/src/util/error_message_utils.dart +++ b/lib/src/util/error_message_utils.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/util/event_handler_error_catcher.dart b/lib/src/util/event_handler_error_catcher.dart index c9bdeed3..d7514b33 100644 --- a/lib/src/util/event_handler_error_catcher.dart +++ b/lib/src/util/event_handler_error_catcher.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/util/is_or_contains.dart b/lib/src/util/is_or_contains.dart index 96f838eb..78a0eda3 100644 --- a/lib/src/util/is_or_contains.dart +++ b/lib/src/util/is_or_contains.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/src/util/js_utils.dart b/lib/src/util/js_utils.dart index 46e1828c..46fcf465 100644 --- a/lib/src/util/js_utils.dart +++ b/lib/src/util/js_utils.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/user_event.dart b/lib/user_event.dart index 8651486e..4859919f 100644 --- a/lib/user_event.dart +++ b/lib/user_event.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/console_log_utils_test.dart b/test/unit/console_log_utils_test.dart index 5170814c..9de1363f 100644 --- a/test/unit/console_log_utils_test.dart +++ b/test/unit/console_log_utils_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -315,8 +314,7 @@ void main() { }); test('with nested components', () { - final logs = recordConsoleLogs(() => rtl.render(Sample({}, Sample2({}))), - configuration: ConsoleConfig.error); + final logs = recordConsoleLogs(() => rtl.render(Sample({}, Sample2({}))), configuration: ConsoleConfig.error); expect( logs, diff --git a/test/unit/dom/accessibility_helpers_test.dart b/test/unit/dom/accessibility_helpers_test.dart index 8e3077bb..2e57b461 100644 --- a/test/unit/dom/accessibility_helpers_test.dart +++ b/test/unit/dom/accessibility_helpers_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/dom/configure_test.dart b/test/unit/dom/configure_test.dart index fdc79b9c..aa85f273 100644 --- a/test/unit/dom/configure_test.dart +++ b/test/unit/dom/configure_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/dom/fire_event_test.dart b/test/unit/dom/fire_event_test.dart index 5770869e..204a7a3d 100644 --- a/test/unit/dom/fire_event_test.dart +++ b/test/unit/dom/fire_event_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/dom/matchers/contains_element_test.dart b/test/unit/dom/matchers/contains_element_test.dart index 14f9788d..57546fd2 100644 --- a/test/unit/dom/matchers/contains_element_test.dart +++ b/test/unit/dom/matchers/contains_element_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/dom/matchers/css_class_matchers_test.dart b/test/unit/dom/matchers/css_class_matchers_test.dart index 05d2775d..1b64fab4 100644 --- a/test/unit/dom/matchers/css_class_matchers_test.dart +++ b/test/unit/dom/matchers/css_class_matchers_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/dom/matchers/has_attribute_test.dart b/test/unit/dom/matchers/has_attribute_test.dart index f5acaf66..2fa81ff7 100644 --- a/test/unit/dom/matchers/has_attribute_test.dart +++ b/test/unit/dom/matchers/has_attribute_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/dom/matchers/has_description_test.dart b/test/unit/dom/matchers/has_description_test.dart index 4182b002..a8da5955 100644 --- a/test/unit/dom/matchers/has_description_test.dart +++ b/test/unit/dom/matchers/has_description_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/dom/matchers/has_form_values_test.dart b/test/unit/dom/matchers/has_form_values_test.dart index 92008cb7..a890656f 100644 --- a/test/unit/dom/matchers/has_form_values_test.dart +++ b/test/unit/dom/matchers/has_form_values_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/dom/matchers/has_styles_test.dart b/test/unit/dom/matchers/has_styles_test.dart index c2bacc3f..ce1e6124 100644 --- a/test/unit/dom/matchers/has_styles_test.dart +++ b/test/unit/dom/matchers/has_styles_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/dom/matchers/has_text_content_test.dart b/test/unit/dom/matchers/has_text_content_test.dart index 371f2c3a..56709f93 100644 --- a/test/unit/dom/matchers/has_text_content_test.dart +++ b/test/unit/dom/matchers/has_text_content_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/dom/matchers/has_value_test.dart b/test/unit/dom/matchers/has_value_test.dart index 77d3ed6c..5a8b5c72 100644 --- a/test/unit/dom/matchers/has_value_test.dart +++ b/test/unit/dom/matchers/has_value_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/dom/matchers/is_checked_test.dart b/test/unit/dom/matchers/is_checked_test.dart index 6ed49c1c..748cbdba 100644 --- a/test/unit/dom/matchers/is_checked_test.dart +++ b/test/unit/dom/matchers/is_checked_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/dom/matchers/is_disabled_test.dart b/test/unit/dom/matchers/is_disabled_test.dart index b8525a33..84c2d425 100644 --- a/test/unit/dom/matchers/is_disabled_test.dart +++ b/test/unit/dom/matchers/is_disabled_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/dom/matchers/is_empty_dom_element_test.dart b/test/unit/dom/matchers/is_empty_dom_element_test.dart index eb3c2f9e..2400bee4 100644 --- a/test/unit/dom/matchers/is_empty_dom_element_test.dart +++ b/test/unit/dom/matchers/is_empty_dom_element_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/dom/matchers/is_focused_test.dart b/test/unit/dom/matchers/is_focused_test.dart index 9813939f..103155e3 100644 --- a/test/unit/dom/matchers/is_focused_test.dart +++ b/test/unit/dom/matchers/is_focused_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/dom/matchers/is_in_the_document_test.dart b/test/unit/dom/matchers/is_in_the_document_test.dart index cda007c3..2a4517c4 100644 --- a/test/unit/dom/matchers/is_in_the_document_test.dart +++ b/test/unit/dom/matchers/is_in_the_document_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/dom/matchers/is_partially_checked_test.dart b/test/unit/dom/matchers/is_partially_checked_test.dart index ab790288..9db71c4a 100644 --- a/test/unit/dom/matchers/is_partially_checked_test.dart +++ b/test/unit/dom/matchers/is_partially_checked_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/dom/pretty_dom_test.dart b/test/unit/dom/pretty_dom_test.dart index 1d04c8b7..2c75129f 100644 --- a/test/unit/dom/pretty_dom_test.dart +++ b/test/unit/dom/pretty_dom_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/dom/queries/by_label_text_test.dart b/test/unit/dom/queries/by_label_text_test.dart index 2c6ac580..b7225432 100644 --- a/test/unit/dom/queries/by_label_text_test.dart +++ b/test/unit/dom/queries/by_label_text_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/dom/queries/by_role_test.dart b/test/unit/dom/queries/by_role_test.dart index 59fdb00f..399e4817 100644 --- a/test/unit/dom/queries/by_role_test.dart +++ b/test/unit/dom/queries/by_role_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/dom/queries/by_testid_test.dart b/test/unit/dom/queries/by_testid_test.dart index 96980a45..e4370418 100644 --- a/test/unit/dom/queries/by_testid_test.dart +++ b/test/unit/dom/queries/by_testid_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/dom/queries/by_text_test.dart b/test/unit/dom/queries/by_text_test.dart index 7ab8b7de..b9375051 100644 --- a/test/unit/dom/queries/by_text_test.dart +++ b/test/unit/dom/queries/by_text_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/dom/queries/shared/scoped_queries_tests.dart b/test/unit/dom/queries/shared/scoped_queries_tests.dart index 1455c0ec..523c7f21 100644 --- a/test/unit/dom/queries/shared/scoped_queries_tests.dart +++ b/test/unit/dom/queries/shared/scoped_queries_tests.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/dom/queries/shared/text_match_type_parsing_tests.dart b/test/unit/dom/queries/shared/text_match_type_parsing_tests.dart index e4d0dde7..75c98e40 100644 --- a/test/unit/dom/queries/shared/text_match_type_parsing_tests.dart +++ b/test/unit/dom/queries/shared/text_match_type_parsing_tests.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/dom/top_level_queries_test.dart b/test/unit/dom/top_level_queries_test.dart index e82452dd..967d6b74 100644 --- a/test/unit/dom/top_level_queries_test.dart +++ b/test/unit/dom/top_level_queries_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -92,9 +91,7 @@ void main() { }) { final elsForQuerying = elementsForQuerying(scopeName, renderMultipleElsMatchingQuery: renderMultipleElsMatchingQuery); - final els = testAsyncQuery - ? DelayedRenderOf({'childrenToRenderAfterDelay': elsForQuerying}) - : elsForQuerying; + final els = testAsyncQuery ? DelayedRenderOf({'childrenToRenderAfterDelay': elsForQuerying}) : elsForQuerying; final view = rtl.render(els); container = view.container; expectedPrettyDom = rtl.prettyDOM(container); diff --git a/test/unit/dom/wait_for_test.dart b/test/unit/dom/wait_for_test.dart index 8b470793..af621b8e 100644 --- a/test/unit/dom/wait_for_test.dart +++ b/test/unit/dom/wait_for_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/dom/within_test.dart b/test/unit/dom/within_test.dart index 856d5a65..3da2f8e9 100644 --- a/test/unit/dom/within_test.dart +++ b/test/unit/dom/within_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -36,9 +35,7 @@ void main() { }) { final elsForQuerying = elementsForQuerying(scopeName, renderMultipleElsMatchingQuery: renderMultipleElsMatchingQuery); - final els = testAsyncQuery! - ? DelayedRenderOf({'childrenToRenderAfterDelay': elsForQuerying}) - : elsForQuerying; + final els = testAsyncQuery! ? DelayedRenderOf({'childrenToRenderAfterDelay': elsForQuerying}) : elsForQuerying; final view = rtl.render(els); final queries = rtl.within(view.container); return ScopedQueriesTestWrapper(queries, view); diff --git a/test/unit/react/render_test.dart b/test/unit/react/render_test.dart index c20a599e..fb29e7ef 100644 --- a/test/unit/react/render_test.dart +++ b/test/unit/react/render_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -53,9 +52,8 @@ void main() { }) { final elsForQuerying = elementsForQuerying(scopeName, renderMultipleElsMatchingQuery: renderMultipleElsMatchingQuery); - final els = testAsyncQuery! - ? DelayedRenderOf({'childrenToRenderAfterDelay': elsForQuerying}) - : elsForQuerying; + final els = + testAsyncQuery! ? DelayedRenderOf({'childrenToRenderAfterDelay': elsForQuerying}) : elsForQuerying; return ScopedQueriesTestWrapper(rtl.render(els)); }); }); diff --git a/test/unit/user_event/clear_test.dart b/test/unit/user_event/clear_test.dart index 6e2e17c7..206333ab 100644 --- a/test/unit/user_event/clear_test.dart +++ b/test/unit/user_event/clear_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/user_event/click_test.dart b/test/unit/user_event/click_test.dart index 668aee60..f155048f 100644 --- a/test/unit/user_event/click_test.dart +++ b/test/unit/user_event/click_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/user_event/hover_test.dart b/test/unit/user_event/hover_test.dart index d23a73b2..47091a55 100644 --- a/test/unit/user_event/hover_test.dart +++ b/test/unit/user_event/hover_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/user_event/paste_test.dart b/test/unit/user_event/paste_test.dart index 6ded2f98..e0285ac4 100644 --- a/test/unit/user_event/paste_test.dart +++ b/test/unit/user_event/paste_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/user_event/select_options_test.dart b/test/unit/user_event/select_options_test.dart index c9ed4e7d..796f3890 100644 --- a/test/unit/user_event/select_options_test.dart +++ b/test/unit/user_event/select_options_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/user_event/special_chars_test.dart b/test/unit/user_event/special_chars_test.dart index 233fda86..83c0c688 100644 --- a/test/unit/user_event/special_chars_test.dart +++ b/test/unit/user_event/special_chars_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/user_event/tab_test.dart b/test/unit/user_event/tab_test.dart index 9cc275cb..d89baaef 100644 --- a/test/unit/user_event/tab_test.dart +++ b/test/unit/user_event/tab_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/user_event/type_test.dart b/test/unit/user_event/type_test.dart index a2531923..2517aa28 100644 --- a/test/unit/user_event/type_test.dart +++ b/test/unit/user_event/type_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/user_event/upload_test.dart b/test/unit/user_event/upload_test.dart index aa7a2565..ac242b9a 100644 --- a/test/unit/user_event/upload_test.dart +++ b/test/unit/user_event/upload_test.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/util/constants.dart b/test/unit/util/constants.dart index ce0e50bd..7c2ff60f 100644 --- a/test/unit/util/constants.dart +++ b/test/unit/util/constants.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/util/enums.dart b/test/unit/util/enums.dart index e81867f1..63322163 100644 --- a/test/unit/util/enums.dart +++ b/test/unit/util/enums.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/util/event_handler_error.dart b/test/unit/util/event_handler_error.dart index 7d4aaf3c..d3ecfd13 100644 --- a/test/unit/util/event_handler_error.dart +++ b/test/unit/util/event_handler_error.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/util/exception.dart b/test/unit/util/exception.dart index a75d9c8c..b67a356d 100644 --- a/test/unit/util/exception.dart +++ b/test/unit/util/exception.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/util/init.dart b/test/unit/util/init.dart index b7292587..a84b7a04 100644 --- a/test/unit/util/init.dart +++ b/test/unit/util/init.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/util/matchers.dart b/test/unit/util/matchers.dart index b5af8377..c5aa2306 100644 --- a/test/unit/util/matchers.dart +++ b/test/unit/util/matchers.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -39,7 +38,7 @@ Matcher toThrowErrorMatchingInlineSnapshot( final errorNameMatcher = hasToStringValue(contains('TestingLibraryElementError')); final snapshotMatcher = hasToStringValue(stringSnapshotMatcher); final prettyDomMatcher = - // ignore: unnecessary_null_comparison + // ignore: unnecessary_null_comparison stringPrettyDomMatcher != null ? hasToStringValue(stringPrettyDomMatcher) : hasToStringValue(endsWith('')); return throwsA(allOf(isA(), errorNameMatcher, snapshotMatcher, prettyDomMatcher, diff --git a/test/unit/util/over_react_stubs.dart b/test/unit/util/over_react_stubs.dart index 8798437c..0593d306 100644 --- a/test/unit/util/over_react_stubs.dart +++ b/test/unit/util/over_react_stubs.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/util/prints_and_logs_recording.dart b/test/unit/util/prints_and_logs_recording.dart index bca3265f..dd9eed35 100644 --- a/test/unit/util/prints_and_logs_recording.dart +++ b/test/unit/util/prints_and_logs_recording.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/util/rendering.dart b/test/unit/util/rendering.dart index 4790c47f..39b56229 100644 --- a/test/unit/util/rendering.dart +++ b/test/unit/util/rendering.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/util/shadow_dom.dart b/test/unit/util/shadow_dom.dart index c2dd12e8..1b69c4f5 100644 --- a/test/unit/util/shadow_dom.dart +++ b/test/unit/util/shadow_dom.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/test/unit/util/string_trimming.dart b/test/unit/util/string_trimming.dart index c117c80b..3ef08a21 100644 --- a/test/unit/util/string_trimming.dart +++ b/test/unit/util/string_trimming.dart @@ -1,4 +1,3 @@ - // Copyright 2021 Workiva Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); From c22e82fb9284d39481f90481ef4e5ebe8ebdb959 Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Mon, 13 Nov 2023 11:42:52 -0700 Subject: [PATCH 10/31] Update dependency to react-dart 7 --- pubspec.yaml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 5b70a413..8bd841e6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,7 +12,7 @@ dependencies: js: ^0.6.2 matcher: ^0.12.9 meta: ^1.6.0 - react: ^6.0.0 + react: ^7.0.0 test: ^1.14.4 dev_dependencies: @@ -21,9 +21,3 @@ dev_dependencies: build_web_compilers: ">=2.12.0 <4.0.0" test_html_builder: '>=2.2.2 <4.0.0' workiva_analysis_options: ^1.0.0 - -dependency_overrides: - react: - git: - url: https://github.com/Workiva/react-dart - ref: null-safety-manual From 62adb475b5111b207d37273d693e3ceb8bcd1b89 Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Mon, 13 Nov 2023 11:48:31 -0700 Subject: [PATCH 11/31] Fix analysis errors --- test/unit/dom/pretty_dom_test.dart | 2 +- test/unit/dom/queries/by_role_test.dart | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/unit/dom/pretty_dom_test.dart b/test/unit/dom/pretty_dom_test.dart index 2c75129f..fce61e5e 100644 --- a/test/unit/dom/pretty_dom_test.dart +++ b/test/unit/dom/pretty_dom_test.dart @@ -22,7 +22,7 @@ import 'package:test/test.dart'; void main() { group('prettyDOM', () { group('returns a formatted string of the HTML produced by the node provided', () { - late Ref vDomRootRef; + late Ref vDomRootRef; setUp(() { vDomRootRef = react.createRef(); final vDom = react.div( diff --git a/test/unit/dom/queries/by_role_test.dart b/test/unit/dom/queries/by_role_test.dart index 399e4817..4169e12e 100644 --- a/test/unit/dom/queries/by_role_test.dart +++ b/test/unit/dom/queries/by_role_test.dart @@ -29,11 +29,11 @@ void main() { initConfigForInternalTesting(); late rtl.RenderResult view; - late Ref emptyElementRef; + late Ref emptyElementRef; group('when more than one element has the same role,', () { setUp(() { - emptyElementRef = react.createRef(); + emptyElementRef = react.createRef(); view = rtl.render(react.article( {}, react.h1({}, 'Heading'), From 083aa7344a8b33a0469be2a3e6ea7e6786d407e9 Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Mon, 13 Nov 2023 12:05:06 -0700 Subject: [PATCH 12/31] Run CI on 2.19 as well --- .github/workflows/build_and_deploy_docs.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_and_deploy_docs.yml b/.github/workflows/build_and_deploy_docs.yml index c3883e6c..b00cbb97 100644 --- a/.github/workflows/build_and_deploy_docs.yml +++ b/.github/workflows/build_and_deploy_docs.yml @@ -19,7 +19,7 @@ jobs: strategy: fail-fast: false matrix: - sdk: [ 2.18.7 ] + sdk: [ 2.18.7, 2.19.4 ] steps: - uses: actions/checkout@v3 - uses: dart-lang/setup-dart@v1 @@ -50,4 +50,4 @@ jobs: artifact_name: dartdoc if: ${{ steps.build-docs.outcome == 'success' && steps.archive-dartdoc-artifact.outcome == 'success' && github.event_name == 'push' }} - + From ebbcabc4ebb9e46940d88e44e0bccb5985cfb343 Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Mon, 13 Nov 2023 13:15:03 -0700 Subject: [PATCH 13/31] Run CI on 2.19 as well --- .github/workflows/build_and_deploy_docs.yml | 2 +- .github/workflows/dart_ci.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_and_deploy_docs.yml b/.github/workflows/build_and_deploy_docs.yml index b00cbb97..f17895f5 100644 --- a/.github/workflows/build_and_deploy_docs.yml +++ b/.github/workflows/build_and_deploy_docs.yml @@ -19,7 +19,7 @@ jobs: strategy: fail-fast: false matrix: - sdk: [ 2.18.7, 2.19.4 ] + sdk: [ 2.18.7 ] steps: - uses: actions/checkout@v3 - uses: dart-lang/setup-dart@v1 diff --git a/.github/workflows/dart_ci.yml b/.github/workflows/dart_ci.yml index 5c83c4c0..71fc11dc 100644 --- a/.github/workflows/dart_ci.yml +++ b/.github/workflows/dart_ci.yml @@ -15,7 +15,7 @@ jobs: strategy: fail-fast: false matrix: - sdk: [ 2.18.7 ] + sdk: [ 2.18.7, 2.19.4 ] steps: - uses: actions/checkout@v2 - uses: dart-lang/setup-dart@v1 From fab10448b983f13a83d5bdf2b91f0b1019c13177 Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Mon, 13 Nov 2023 13:15:15 -0700 Subject: [PATCH 14/31] Fix hints --- lib/src/dom/queries/by_testid.dart | 2 +- test/unit/dom/accessibility_helpers_test.dart | 27 +++++++------- test/unit/dom/fire_event_test.dart | 3 +- .../dom/matchers/contains_element_test.dart | 7 ++-- .../dom/matchers/has_description_test.dart | 3 +- test/unit/dom/matchers/has_styles_test.dart | 3 +- .../dom/matchers/has_text_content_test.dart | 3 +- test/unit/dom/matchers/has_value_test.dart | 37 +++++++++---------- test/unit/dom/matchers/is_checked_test.dart | 15 ++++---- test/unit/dom/matchers/is_disabled_test.dart | 13 +++---- .../matchers/is_empty_dom_element_test.dart | 7 ++-- .../dom/matchers/is_in_the_document_test.dart | 2 +- test/unit/dom/pretty_dom_test.dart | 4 +- test/unit/dom/queries/by_label_text_test.dart | 3 +- test/unit/dom/queries/by_role_test.dart | 12 +++--- test/unit/dom/queries/by_testid_test.dart | 9 ++--- test/unit/dom/queries/by_text_test.dart | 5 +-- test/unit/dom/text_match_test.dart | 19 +++++----- test/unit/dom/within_test.dart | 3 +- test/unit/react/render_test.dart | 22 +++++------ test/unit/user_event/clear_test.dart | 5 +-- test/unit/user_event/click_test.dart | 7 ++-- test/unit/user_event/hover_test.dart | 6 +-- test/unit/user_event/paste_test.dart | 5 +-- test/unit/user_event/select_options_test.dart | 9 ++--- test/unit/user_event/special_chars_test.dart | 3 +- test/unit/user_event/tab_test.dart | 3 +- test/unit/user_event/type_test.dart | 9 ++--- test/unit/user_event/upload_test.dart | 3 +- test/unit/util/event_handler_error.dart | 5 +-- test/unit/util/rendering.dart | 4 +- 31 files changed, 117 insertions(+), 141 deletions(-) diff --git a/lib/src/dom/queries/by_testid.dart b/lib/src/dom/queries/by_testid.dart index 03799d5a..91fcedc2 100644 --- a/lib/src/dom/queries/by_testid.dart +++ b/lib/src/dom/queries/by_testid.dart @@ -39,7 +39,7 @@ import 'package:react_testing_library/src/dom/async/wait_for.dart'; import 'package:react_testing_library/src/dom/matches/types.dart'; import 'package:react_testing_library/src/dom/queries/interface.dart'; import 'package:react_testing_library/src/util/error_message_utils.dart' - show TestingLibraryElementError, withErrorInterop, withErrorInterop2; + show TestingLibraryElementError, withErrorInterop; /// PRIVATE. Do not export from this library. /// diff --git a/test/unit/dom/accessibility_helpers_test.dart b/test/unit/dom/accessibility_helpers_test.dart index 2e57b461..506d0e4f 100644 --- a/test/unit/dom/accessibility_helpers_test.dart +++ b/test/unit/dom/accessibility_helpers_test.dart @@ -15,7 +15,6 @@ import 'dart:html'; import 'package:react/react.dart' as react; -import 'package:react/react_client.dart'; import 'package:react_testing_library/react_testing_library.dart' as rtl; import 'package:test/test.dart'; @@ -31,7 +30,7 @@ void main() { react.input({}), react.img({}), react.a({'href': '/'}), - ]) as ReactElement); + ])); expect( rtl.getRoles(view.container), equals({ @@ -49,7 +48,7 @@ void main() { react.input({'type': 'number'}), react.table({}), react.h1({}), - ]) as ReactElement); + ])); expect( rtl.getRoles(rtl.screen.container), equals({ @@ -67,7 +66,7 @@ void main() { final view = rtl.render(react.div({}, [ react.button({}), react.img({}), - ]) as ReactElement); + ])); final button = view.getByRole('button'); expect( rtl.getRoles(button), @@ -85,7 +84,7 @@ void main() { view = rtl.render(react.div({}, [ react.div({'aria-hidden': true}, react.img({})), react.div({}, react.button({})), - ]) as ReactElement); + ])); }); test('when `hidden` option is false (default)', () { @@ -117,7 +116,7 @@ void main() { react.input({'type': 'color'}), react.i({}), react.a({}), - ]) as ReactElement); + ])); expect( rtl.getRoles(view.container), equals({ @@ -149,7 +148,7 @@ void main() { }, react.select({})), react.div({'hidden': true, 'data-test-id': 'hidden'}, react.button({}, 'Hidden Button')), react.div({'aria-hidden': true, 'data-test-id': 'aria-hidden'}, react.p({}, 'Hidden Text')), - ]) as ReactElement); + ])); }); test('for inaccessible elements', () { @@ -201,7 +200,7 @@ void main() { react.input({}), react.img({}), react.a({'href': '/'}, 'click me!'), - ]) as ReactElement); + ])); final roleMatches = _getLoggedRoleMatches(view.container); expect(roleMatches, hasLength(3), reason: 'there are 3 roles in view'); @@ -215,7 +214,7 @@ void main() { react.input({}), react.img({}), react.a({'href': '/'}, 'click me!'), - ]) as ReactElement); + ])); final roleMatches = _getLoggedRoleMatches(rtl.screen.container); expect(roleMatches, hasLength(4), reason: 'there are 4 roles in screen'); @@ -230,7 +229,7 @@ void main() { react.button({}, 'Submit'), react.input({'type': 'number'}), react.button({}, 'Another button'), - ]) as ReactElement); + ])); final roleMatches = _getLoggedRoleMatches(view.container); expect(roleMatches, hasLength(2), reason: 'there are 2 roles in view'); @@ -248,7 +247,7 @@ void main() { react.img({}), react.input({'type': 'radio'}), ]), - ]) as ReactElement); + ])); final roleMatches = _getLoggedRoleMatches(view.getByTestId('container')); expect(roleMatches, hasLength(2), reason: 'there are 2 roles in container'); @@ -260,7 +259,7 @@ void main() { final view = rtl.render(react.div({}, [ react.button({}, 'Click here!'), react.img({}), - ]) as ReactElement); + ])); final roleMatches = _getLoggedRoleMatches(view.getByRole('button', name: 'Click here!')); expect(roleMatches, hasLength(1), reason: 'the button has one role'); @@ -275,7 +274,7 @@ void main() { view = rtl.render(react.div({}, [ react.div({'aria-hidden': true}, react.img({})), react.div({}, react.button({})), - ]) as ReactElement); + ])); }); test('when `hidden` option is false (default)', () { @@ -297,7 +296,7 @@ void main() { react.input({'type': 'color'}), react.i({}), react.a({}), - ]) as ReactElement); + ])); final roleMatches = _getLoggedRoleMatches(view.container); expect(roleMatches, isEmpty, reason: 'there is are no roles in view'); }); diff --git a/test/unit/dom/fire_event_test.dart b/test/unit/dom/fire_event_test.dart index 204a7a3d..011e42a3 100644 --- a/test/unit/dom/fire_event_test.dart +++ b/test/unit/dom/fire_event_test.dart @@ -15,7 +15,6 @@ import 'dart:html'; import 'package:react/react.dart' as react; -import 'package:react/react_client.dart' show ReactElement; import 'package:react_testing_library/react_testing_library.dart' as rtl; import 'package:test/test.dart'; @@ -34,7 +33,7 @@ void main() { 'onClick': (event) { calls.add((event as react.SyntheticMouseEvent).nativeEvent as Event); } - }, 'oh hai') as ReactElement; + }, 'oh hai'); view = rtl.render(elementToRender); }); diff --git a/test/unit/dom/matchers/contains_element_test.dart b/test/unit/dom/matchers/contains_element_test.dart index 57546fd2..4864961f 100644 --- a/test/unit/dom/matchers/contains_element_test.dart +++ b/test/unit/dom/matchers/contains_element_test.dart @@ -15,7 +15,6 @@ import 'dart:html' show DivElement; import 'package:react/react.dart' as react; -import 'package:react/react_client.dart' show ReactElement; import 'package:react_testing_library/matchers.dart' show containsElement; import 'package:react_testing_library/react_testing_library.dart' show render; import 'package:react_testing_library/src/matchers/jest_dom/util/constants.dart'; @@ -30,7 +29,7 @@ void main() { final view = render(react.span( {defaultTestIdKey: 'ancestor'}, react.span({defaultTestIdKey: 'direct-descendant'}), - ) as ReactElement); + )); shouldPass(view.getByTestId('ancestor'), containsElement(view.getByTestId('direct-descendant'))); }); @@ -41,7 +40,7 @@ void main() { {defaultTestIdKey: 'direct-descendant'}, react.span({defaultTestIdKey: 'descendant'}), ), - ) as ReactElement); + )); shouldPass(view.getByTestId('ancestor'), containsElement(view.getByTestId('descendant'))); }); @@ -52,7 +51,7 @@ void main() { test('the matched item does not have a matching descendant', () { final view = render( - react.span({defaultTestIdKey: 'ancestor'}, react.span({defaultTestIdKey: 'descendant'})) as ReactElement); + react.span({defaultTestIdKey: 'ancestor'}, react.span({defaultTestIdKey: 'descendant'}))); final ancestor = view.getByTestId('ancestor'); final descendant = view.getByTestId('descendant'); shouldFail(descendant, containsElement(ancestor), contains('Which: does not contain $ancestor.')); diff --git a/test/unit/dom/matchers/has_description_test.dart b/test/unit/dom/matchers/has_description_test.dart index a8da5955..b6bf7d7d 100644 --- a/test/unit/dom/matchers/has_description_test.dart +++ b/test/unit/dom/matchers/has_description_test.dart @@ -15,7 +15,6 @@ import 'dart:html' show Element, querySelector; import 'package:react/react.dart' as react; -import 'package:react/react_client.dart' show ReactElement; import 'package:react_testing_library/matchers.dart' show hasDescription; import 'package:react_testing_library/react_testing_library.dart' show render, RenderResult; import 'package:react_testing_library/src/matchers/jest_dom/util/constants.dart'; @@ -42,7 +41,7 @@ void main() { react.button({'aria-describedby': 'not-found'}, 'Has id not found'), react.div({'id': 'description-close'}, 'Closing will discard any changes'), react.div({'id': 'some-other-description'}, 'Some other description'), - ) as ReactElement); + )); }); group('[element with a single id as its aria-describedby attribute value]', () { diff --git a/test/unit/dom/matchers/has_styles_test.dart b/test/unit/dom/matchers/has_styles_test.dart index ce1e6124..442c1d3b 100644 --- a/test/unit/dom/matchers/has_styles_test.dart +++ b/test/unit/dom/matchers/has_styles_test.dart @@ -15,7 +15,6 @@ import 'dart:html'; import 'package:react/react.dart' as react; -import 'package:react/react_client.dart' show ReactElement; import 'package:react_testing_library/matchers.dart' show hasStyles; import 'package:react_testing_library/react_testing_library.dart' show render, RenderResult; import 'package:react_testing_library/src/matchers/jest_dom/util/constants.dart'; @@ -54,7 +53,7 @@ void main() { 'zIndex': 2, }, 'title': 'this is the title' - }) as ReactElement); + })); }); group('passes', () { diff --git a/test/unit/dom/matchers/has_text_content_test.dart b/test/unit/dom/matchers/has_text_content_test.dart index 56709f93..5af7e418 100644 --- a/test/unit/dom/matchers/has_text_content_test.dart +++ b/test/unit/dom/matchers/has_text_content_test.dart @@ -15,7 +15,6 @@ import 'dart:html' show Element; import 'package:react/react.dart' as react; -import 'package:react/react_client.dart' show ReactElement; import 'package:react_testing_library/matchers.dart' show hasTextContent; import 'package:react_testing_library/react_testing_library.dart' show render; import 'package:react_testing_library/src/matchers/jest_dom/util/constants.dart'; @@ -30,7 +29,7 @@ void main() { setUp(() { final view = render( - react.span({defaultTestIdKey: 'root'}, 'The quick brown fox jumps over the (lazy) dog') as ReactElement); + react.span({defaultTestIdKey: 'root'}, 'The quick brown fox jumps over the (lazy) dog')); rootElement = view.getByTestId('root'); }); diff --git a/test/unit/dom/matchers/has_value_test.dart b/test/unit/dom/matchers/has_value_test.dart index 5a8b5c72..0051290a 100644 --- a/test/unit/dom/matchers/has_value_test.dart +++ b/test/unit/dom/matchers/has_value_test.dart @@ -14,7 +14,6 @@ import 'package:meta/meta.dart'; import 'package:react/react.dart' as react; -import 'package:react/react_client.dart' show ReactElement; import 'package:react_testing_library/matchers.dart' show hasDisplayValue, hasValue; import 'package:react_testing_library/react_testing_library.dart' show render, RenderResult; import 'package:react_testing_library/src/matchers/jest_dom/util/constants.dart'; @@ -40,7 +39,7 @@ void sharedHasValueTests(String description, 'type': 'text', 'name': 'firstName', 'defaultValue': 'John', - }) as ReactElement); + })); }); test('exact match', () { @@ -62,7 +61,7 @@ void sharedHasValueTests(String description, view = render(react.textarea({ 'name': 'comment', 'defaultValue': 'I am here to say something nice about you', - }) as ReactElement); + })); }); test('exact match', () { @@ -80,7 +79,7 @@ void sharedHasValueTests(String description, 'type': 'number', 'name': 'age', 'defaultValue': 35, - }) as ReactElement); + })); }); test('exact match', () { @@ -107,7 +106,7 @@ void sharedHasValueTests(String description, react.option({ 'value': 'business', }, 'business description'), - ) as ReactElement); + )); if (matcherFn == hasValue) { shouldPass(view.getByRole('combobox'), matcherFn('business')); @@ -125,7 +124,7 @@ void sharedHasValueTests(String description, react.option({ 'value': 'business', }, 'business description'), - ) as ReactElement); + )); if (matcherFn == hasValue) { shouldPass( @@ -156,7 +155,7 @@ void sharedHasValueTests(String description, 'value': 'business', 'disabled': true, }, 'business'), - ) as ReactElement); + )); shouldPass(view.getByRole('combobox'), matcherFn()); }); @@ -181,7 +180,7 @@ void sharedHasValueTests(String description, 'value': 'pineapple', 'disabled': true, }, 'Processed Sweetened Pineapple'), - ) as ReactElement); + )); }); test('exact match', () { @@ -229,7 +228,7 @@ void sharedHasValueTests(String description, 'value': 'pineapple', 'disabled': true, }, 'Processed Sweetened Pineapple'), - ) as ReactElement); + )); }); test('exact match', () { @@ -267,7 +266,7 @@ void sharedHasValueTests(String description, 'value': 'pineapple', 'disabled': true, }, 'pineapple description'), - ) as ReactElement); + )); shouldPass(view.getByRole('listbox'), matcherFn()); }); @@ -286,7 +285,7 @@ void sharedHasValueTests(String description, 'type': 'checkbox', 'name': 'business-in-front', 'defaultChecked': true, - }) as ReactElement); + })); shouldFail( view.getByRole('checkbox'), @@ -299,7 +298,7 @@ void sharedHasValueTests(String description, view = render(react.div({ 'role': 'checkbox', 'aria-checked': 'true', - }) as ReactElement); + })); shouldFail( view.getByRole('checkbox'), @@ -313,7 +312,7 @@ void sharedHasValueTests(String description, 'type': 'radio', 'name': 'business-in-front', 'defaultChecked': true, - }) as ReactElement); + })); shouldFail( view.getByRole('radio'), @@ -326,7 +325,7 @@ void sharedHasValueTests(String description, view = render(react.div({ 'role': 'radio', 'aria-checked': 'true', - }) as ReactElement); + })); shouldFail( view.getByRole('radio'), @@ -342,7 +341,7 @@ void sharedHasValueTests(String description, 'type': 'text', 'name': 'firstName', 'defaultValue': 'John', - }) as ReactElement); + })); shouldFail( view.getByRole('textbox'), @@ -358,7 +357,7 @@ void sharedHasValueTests(String description, view = render(react.textarea({ 'name': 'comments', 'defaultValue': 'I have nothing nice to say', - }) as ReactElement); + })); shouldFail( view.getByRole('textbox'), @@ -375,7 +374,7 @@ void sharedHasValueTests(String description, 'type': 'number', 'name': 'age', 'defaultValue': 35, - }) as ReactElement); + })); shouldFail( view.getByRole('spinbutton'), @@ -400,7 +399,7 @@ void sharedHasValueTests(String description, react.option({ 'value': 'business', }, 'business description'), - ) as ReactElement); + )); if (matcherFn == hasValue) { shouldFail( @@ -440,7 +439,7 @@ void sharedHasValueTests(String description, 'value': 'pineapple', 'disabled': true, }, 'Processed Sweetened Pineapple'), - ) as ReactElement); + )); if (matcherFn == hasValue) { shouldFail( diff --git a/test/unit/dom/matchers/is_checked_test.dart b/test/unit/dom/matchers/is_checked_test.dart index 748cbdba..f514a471 100644 --- a/test/unit/dom/matchers/is_checked_test.dart +++ b/test/unit/dom/matchers/is_checked_test.dart @@ -13,7 +13,6 @@ // limitations under the License. import 'package:react/react.dart' as react; -import 'package:react/react_client.dart' show ReactElement; import 'package:react_testing_library/matchers.dart' show isChecked; import 'package:react_testing_library/react_testing_library.dart' show render; import 'package:react_testing_library/src/matchers/jest_dom/util/constants.dart'; @@ -29,7 +28,7 @@ void main() { final view = render(react.input({ 'type': 'checkbox', 'defaultChecked': true, - }) as ReactElement); + })); shouldPass(view.getByRole('checkbox'), isChecked); }); @@ -37,7 +36,7 @@ void main() { final view = render(react.div({ 'role': 'checkbox', 'aria-checked': 'true', - }) as ReactElement); + })); shouldPass(view.getByRole('checkbox'), isChecked); }); @@ -46,7 +45,7 @@ void main() { 'type': 'radio', 'name': 'something', 'defaultChecked': true, - }) as ReactElement); + })); shouldPass(view.getByRole('radio'), isChecked); }); @@ -54,7 +53,7 @@ void main() { final view = render(react.div({ 'role': 'radio', 'aria-checked': 'true', - }) as ReactElement); + })); shouldPass(view.getByRole('radio'), isChecked); }); @@ -62,7 +61,7 @@ void main() { final view = render(react.div({ 'role': 'switch', 'aria-checked': 'true', - }) as ReactElement); + })); shouldPass(view.getByRole('switch'), isChecked); }); }); @@ -74,7 +73,7 @@ void main() { group('the matched item is not a type of element that can be checked', () { test('', () { - final view = render(react.div({defaultTestIdKey: 'div'}) as ReactElement); + final view = render(react.div({defaultTestIdKey: 'div'})); final divNode = view.getByTestId('div'); shouldFail(divNode, isChecked, contains('Which: is not a type of HTML Element that can be checked.')); }); @@ -84,7 +83,7 @@ void main() { final view = render(react.input({ 'type': 'checkbox', 'defaultChecked': false, - }) as ReactElement); + })); shouldFail(view.getByRole('checkbox'), isChecked, contains('Which: is not checked.')); }); }); diff --git a/test/unit/dom/matchers/is_disabled_test.dart b/test/unit/dom/matchers/is_disabled_test.dart index 84c2d425..c56912d4 100644 --- a/test/unit/dom/matchers/is_disabled_test.dart +++ b/test/unit/dom/matchers/is_disabled_test.dart @@ -15,7 +15,6 @@ import 'dart:html' show InputElement; import 'package:react/react.dart' as react; -import 'package:react/react_client.dart' show ReactElement; import 'package:react_testing_library/matchers.dart' show isDisabled, isEnabled; import 'package:react_testing_library/react_testing_library.dart' show render; import 'package:react_testing_library/src/matchers/jest_dom/util/constants.dart'; @@ -30,12 +29,12 @@ void main() { test('is disabled', () { shouldPass(InputElement()..disabled = true, isDisabled); final view = render( - react.form({'disabled': true, defaultTestIdKey: 'form'}, react.button({'type': 'submit'})) as ReactElement); + react.form({'disabled': true, defaultTestIdKey: 'form'}, react.button({'type': 'submit'}))); shouldPass(view.getByTestId('form'), isDisabled); }); test('within a disabled FormElement', () { - final view = render(react.form({'disabled': true}, react.button({'type': 'submit'})) as ReactElement); + final view = render(react.form({'disabled': true}, react.button({'type': 'submit'}))); shouldPass(view.getByRole('button'), isDisabled); }); }); @@ -47,13 +46,13 @@ void main() { group('the matched item is not a type of element that can be disabled', () { test('', () { - final view = render(react.div({defaultTestIdKey: 'div'}) as ReactElement); + final view = render(react.div({defaultTestIdKey: 'div'})); final divNode = view.getByTestId('div'); shouldFail(divNode, isDisabled, contains('Which: is not a type of HTML Element that can be disabled.')); }); test('even when nested within a FormElement that is disabled', () { - final view = render(react.form({'disabled': true}, react.div({defaultTestIdKey: 'div'})) as ReactElement); + final view = render(react.form({'disabled': true}, react.div({defaultTestIdKey: 'div'}))); final divNode = view.getByTestId('div'); shouldFail(divNode, isDisabled, contains('Which: is not a type of HTML Element that can be disabled.')); }); @@ -79,13 +78,13 @@ void main() { group('the matched item is not a type of element that can be disabled', () { test('', () { - final view = render(react.div({defaultTestIdKey: 'div'}) as ReactElement); + final view = render(react.div({defaultTestIdKey: 'div'})); final divNode = view.getByTestId('div'); shouldFail(divNode, isEnabled, contains('Which: is not a type of HTML Element that can be disabled.')); }); test('even when nested within a FormElement that is disabled', () { - final view = render(react.form({'disabled': true}, react.div({defaultTestIdKey: 'div'})) as ReactElement); + final view = render(react.form({'disabled': true}, react.div({defaultTestIdKey: 'div'}))); final divNode = view.getByTestId('div'); shouldFail(divNode, isEnabled, contains('Which: is not a type of HTML Element that can be disabled.')); }); diff --git a/test/unit/dom/matchers/is_empty_dom_element_test.dart b/test/unit/dom/matchers/is_empty_dom_element_test.dart index 2400bee4..9f414770 100644 --- a/test/unit/dom/matchers/is_empty_dom_element_test.dart +++ b/test/unit/dom/matchers/is_empty_dom_element_test.dart @@ -13,7 +13,6 @@ // limitations under the License. import 'package:react/react.dart' as react; -import 'package:react/react_client.dart' show ReactElement; import 'package:react_testing_library/matchers.dart' show isEmptyDomElement; import 'package:react_testing_library/react_testing_library.dart' show render; import 'package:react_testing_library/src/matchers/jest_dom/util/constants.dart'; @@ -26,7 +25,7 @@ void main() { group('isEmptyDomElement matcher', () { group('passes when provided a valid Element', () { test('that has no children', () { - final view = render(react.span({defaultTestIdKey: 'empty'}) as ReactElement); + final view = render(react.span({defaultTestIdKey: 'empty'})); shouldPass(view.getByTestId('empty'), isEmptyDomElement); }); }); @@ -38,12 +37,12 @@ void main() { test('the matched item has empty children', () { final view = render( - react.span({defaultTestIdKey: 'not-empty'}, react.span({defaultTestIdKey: 'empty'})) as ReactElement); + react.span({defaultTestIdKey: 'not-empty'}, react.span({defaultTestIdKey: 'empty'}))); shouldFail(view.getByTestId('not-empty'), isEmptyDomElement, contains('Which: is not an empty DOM Element.')); }); test('the matched item has text children', () { - final view = render(react.span({defaultTestIdKey: 'not-empty'}, 'oh hai') as ReactElement); + final view = render(react.span({defaultTestIdKey: 'not-empty'}, 'oh hai')); shouldFail(view.getByTestId('not-empty'), isEmptyDomElement, contains('Which: is not an empty DOM Element.')); }); }); diff --git a/test/unit/dom/matchers/is_in_the_document_test.dart b/test/unit/dom/matchers/is_in_the_document_test.dart index 2a4517c4..a422e59d 100644 --- a/test/unit/dom/matchers/is_in_the_document_test.dart +++ b/test/unit/dom/matchers/is_in_the_document_test.dart @@ -28,7 +28,7 @@ import '../../util/shadow_dom.dart'; void main() { group('isInTheDocument matcher', () { test('passes when provided an element found in the document', () { - final view = render(react.span({defaultTestIdKey: 'empty'}) as ReactElement); + final view = render(react.span({defaultTestIdKey: 'empty'})); shouldPass(view.getByTestId('empty'), isInTheDocument); }); diff --git a/test/unit/dom/pretty_dom_test.dart b/test/unit/dom/pretty_dom_test.dart index fce61e5e..e84fa89a 100644 --- a/test/unit/dom/pretty_dom_test.dart +++ b/test/unit/dom/pretty_dom_test.dart @@ -15,7 +15,7 @@ import 'dart:html'; import 'package:react/react.dart' as react; -import 'package:react/react_client.dart' show ReactElement, Ref; +import 'package:react/react_client.dart' show Ref; import 'package:react_testing_library/react_testing_library.dart' as rtl; import 'package:test/test.dart'; @@ -32,7 +32,7 @@ void main() { {}, react.p({}, 'you again?'), ), - ) as ReactElement; + ); rtl.render(vDom); }); diff --git a/test/unit/dom/queries/by_label_text_test.dart b/test/unit/dom/queries/by_label_text_test.dart index b7225432..6472e2b6 100644 --- a/test/unit/dom/queries/by_label_text_test.dart +++ b/test/unit/dom/queries/by_label_text_test.dart @@ -15,7 +15,6 @@ import 'dart:html'; import 'package:react/react.dart' as react; -import 'package:react/react_client.dart' show ReactElement; import 'package:react_testing_library/react_testing_library.dart' as rtl; import 'package:react_testing_library/src/util/error_message_utils.dart'; import 'package:test/test.dart'; @@ -46,7 +45,7 @@ void main() { 'Username', react.textarea({}), ), - ) as ReactElement); + )); expect(view.queryAllByLabelText('Username'), hasLength(2)); }); diff --git a/test/unit/dom/queries/by_role_test.dart b/test/unit/dom/queries/by_role_test.dart index 4169e12e..b6943a11 100644 --- a/test/unit/dom/queries/by_role_test.dart +++ b/test/unit/dom/queries/by_role_test.dart @@ -55,7 +55,7 @@ void main() { renderCheckbox(checked: true), renderCheckboxWithSwitchAsFallback(), react.div({'ref': emptyElementRef}), - ) as ReactElement); + )); expect(emptyElementRef.current, isNotNull); expect(view.queryAllByRole('button'), hasLength(greaterThan(1))); @@ -764,14 +764,14 @@ ReactElement renderButton({bool pressed = false, bool expanded = false}) { 'aria-expanded': expanded, }, 'Click me', - ) as ReactElement; + ); } ReactElement renderDialog() { return react.div( {'role': 'dialog'}, 'Read me', - ) as ReactElement; + ); } ReactElement renderTab({bool selected = false}) { @@ -782,7 +782,7 @@ ReactElement renderTab({bool selected = false}) { 'aria-selected': selected, }, 'Select me', - ) as ReactElement; + ); } ReactElement renderCheckbox({bool checked = false}) { @@ -793,7 +793,7 @@ ReactElement renderCheckbox({bool checked = false}) { 'aria-checked': checked, }, 'Check me out', - ) as ReactElement; + ); } ReactElement renderCheckboxWithSwitchAsFallback({bool checked = false}) { @@ -804,5 +804,5 @@ ReactElement renderCheckboxWithSwitchAsFallback({bool checked = false}) { 'aria-checked': checked, }, 'Check me out', - ) as ReactElement; + ); } diff --git a/test/unit/dom/queries/by_testid_test.dart b/test/unit/dom/queries/by_testid_test.dart index e4370418..437680f1 100644 --- a/test/unit/dom/queries/by_testid_test.dart +++ b/test/unit/dom/queries/by_testid_test.dart @@ -15,7 +15,6 @@ import 'dart:html'; import 'package:react/react.dart' as react; -import 'package:react/react_client.dart' show ReactElement; import 'package:react_testing_library/react_testing_library.dart' as rtl; import 'package:react_testing_library/src/util/error_message_utils.dart'; import 'package:test/test.dart'; @@ -43,7 +42,7 @@ void main() { }, 'Testing multiple'), react.span({ 'data-test-id': 'testId-2', - }, 'Testing duplicate')) as ReactElement); + }, 'Testing duplicate'))); }); group('getByTestId', () { @@ -189,7 +188,7 @@ void main() { ' (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()); }); @@ -266,7 +265,7 @@ void main() { ' (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()); }); @@ -287,7 +286,7 @@ void main() { }, 'Testing single'), react.span({ 'data-test-id': 'testId-3 testId-2 testId-1', - }, 'Testing single')) as ReactElement); + }, 'Testing single'))); }); group('getByTestId', () { diff --git a/test/unit/dom/queries/by_text_test.dart b/test/unit/dom/queries/by_text_test.dart index b9375051..3ab8abe2 100644 --- a/test/unit/dom/queries/by_text_test.dart +++ b/test/unit/dom/queries/by_text_test.dart @@ -15,7 +15,6 @@ import 'dart:html'; import 'package:react/react.dart' as react; -import 'package:react/react_client.dart' show ReactElement; import 'package:react_testing_library/react_testing_library.dart' as rtl; import 'package:react_testing_library/src/util/error_message_utils.dart'; import 'package:test/test.dart'; @@ -44,7 +43,7 @@ void main() { {}, 'Foo', ), - ) as ReactElement); + )); expect(view.queryAllByText('Foo'), hasLength(2)); }); @@ -149,7 +148,7 @@ void main() { {}, 'Foo', ), - ) as ReactElement); + )); }); group('can be set to a String query to ignore certain elements matching the selector query:', () { diff --git a/test/unit/dom/text_match_test.dart b/test/unit/dom/text_match_test.dart index 0c55febd..b165a84d 100644 --- a/test/unit/dom/text_match_test.dart +++ b/test/unit/dom/text_match_test.dart @@ -15,7 +15,6 @@ // limitations under the License. import 'package:react/react.dart' as react; -import 'package:react/react_client.dart' show ReactElement; import 'package:react_testing_library/react_testing_library.dart' as rtl; import 'package:test/test.dart'; @@ -48,7 +47,7 @@ void main() { $stackTraceHeading'''; setUp(() { - view = rtl.render(react.img({'alt': actualText}) as ReactElement); + view = rtl.render(react.img({'alt': actualText})); }); test('with a RegExp TextMatch arg value', () { @@ -114,7 +113,7 @@ void main() { $stackTraceHeading'''; setUp(() { - view = rtl.render(react.input({'defaultValue': actualValue}) as ReactElement); + view = rtl.render(react.input({'defaultValue': actualValue})); }); test('with a RegExp TextMatch arg value', () { @@ -186,7 +185,7 @@ void main() { {}, actualText, react.input({}), - ) as ReactElement, + ), ); }); @@ -254,7 +253,7 @@ void main() { $stackTraceHeading'''; setUp(() { - view = rtl.render(react.input({'type': 'text', 'placeholder': actualText}) as ReactElement); + view = rtl.render(react.input({'type': 'text', 'placeholder': actualText})); }); test('with a RegExp TextMatch arg value', () { @@ -319,7 +318,7 @@ void main() { $stackTraceHeading'''; setUp(() { - view = rtl.render(react.button({}, 'Hello') as ReactElement); + view = rtl.render(react.button({}, 'Hello')); }); test('with a RegExp TextMatch arg value', () { @@ -385,7 +384,7 @@ void main() { $stackTraceHeading'''; setUp(() { - view = rtl.render(react.button({}, actualName) as ReactElement); + view = rtl.render(react.button({}, actualName)); }); test('with a RegExp TextMatch arg value', () { @@ -453,7 +452,7 @@ void main() { $stackTraceHeading'''; setUp(() { - view = rtl.render(react.div({defaultTestIdKey: actualTestId}, 'Hello') as ReactElement); + view = rtl.render(react.div({defaultTestIdKey: actualTestId}, 'Hello')); }); test('with a RegExp TextMatch arg value', () { @@ -525,7 +524,7 @@ This could be because the text is broken up by multiple elements. In this case, $stackTraceHeading'''; setUp(() { - view = rtl.render(react.div({}, actualText) as ReactElement); + view = rtl.render(react.div({}, actualText)); }); test('with a RegExp TextMatch arg value', () { @@ -591,7 +590,7 @@ This could be because the text is broken up by multiple elements. In this case, $stackTraceHeading'''; setUp(() { - view = rtl.render(react.div({'title': actualTitle}, 'Hello') as ReactElement); + view = rtl.render(react.div({'title': actualTitle}, 'Hello')); }); test('with a RegExp TextMatch arg value', () { diff --git a/test/unit/dom/within_test.dart b/test/unit/dom/within_test.dart index 3da2f8e9..a0cc58c7 100644 --- a/test/unit/dom/within_test.dart +++ b/test/unit/dom/within_test.dart @@ -15,7 +15,6 @@ import 'dart:html'; import 'package:react/react.dart' as react; -import 'package:react/react_client.dart' show ReactElement; import 'package:react_testing_library/dom/queries.dart' show WithinQueries; import 'package:react_testing_library/react_testing_library.dart' as rtl; import 'package:test/test.dart'; @@ -66,7 +65,7 @@ void main() { 'defaultValue': '3', 'key': 2, }) - ]) as ReactElement); + ])); final printCalls = recordPrintCalls(rtl.screen.debug); expect(printCalls, [ diff --git a/test/unit/react/render_test.dart b/test/unit/react/render_test.dart index fb29e7ef..394d2092 100644 --- a/test/unit/react/render_test.dart +++ b/test/unit/react/render_test.dart @@ -33,7 +33,7 @@ void main() { group('returns a RenderResult', () { test('', () { - final elementToRender = react.div({'id': 'root'}, 'oh hai') as ReactElement; + final elementToRender = react.div({'id': 'root'}, 'oh hai'); final view = rtl.render(elementToRender); expect(view.container, isA()); expect(view.baseElement, isA()); @@ -67,7 +67,7 @@ void main() { 'defaultValue': '3', 'key': 2, }) - ]) as ReactElement); + ])); final printCalls = recordPrintCalls(view.debug); expect(printCalls, [ @@ -89,22 +89,22 @@ void main() { group('renders the provided element in a default container', () { test('', () { - final view = rtl.render(react.div({'id': 'root'}, 'oh hai') as ReactElement); + final view = rtl.render(react.div({'id': 'root'}, 'oh hai')); expect(document.body!.contains(view.container), isTrue); expect(view.container.childNodes, hasLength(1)); expect(view.container.childNodes.single.text, 'oh hai'); }); test('wrapped in a wrapper when specified', () { - rtl.render(react.div({'id': 'root'}, 'oh hai') as ReactElement, wrapper: react.aside); + rtl.render(react.div({'id': 'root'}, 'oh hai'), wrapper: react.aside); final wrapperElement = querySelector('aside')!; expect(wrapperElement, isNotNull); expect(wrapperElement.querySelector('#root'), isNotNull); }); test('and then updates the DOM when rerender is called', () { - final view = rtl.render(react.div({'id': 'root'}, 'oh hai') as ReactElement); - final elementForRerender = react.div({'id': 'root'}, 'different') as ReactElement; + final view = rtl.render(react.div({'id': 'root'}, 'oh hai')); + final elementForRerender = react.div({'id': 'root'}, 'different'); view.rerender(elementForRerender); expect(view.container.childNodes, hasLength(1)); expect(view.container.childNodes.single.text, 'different'); @@ -119,7 +119,7 @@ void main() { calls.clear(); }); - rtl.render(react.div({'id': 'root'}, 'oh hai') as ReactElement, onDidTearDown: () { + rtl.render(react.div({'id': 'root'}, 'oh hai'), onDidTearDown: () { calls.add('autoTearDownCallback'); }); }); @@ -133,7 +133,7 @@ void main() { }); test('', () { - view = rtl.render(react.div({'id': 'root'}, 'oh hai') as ReactElement, autoTearDown: false); + view = rtl.render(react.div({'id': 'root'}, 'oh hai'), autoTearDown: false); }); test('', () { @@ -149,7 +149,7 @@ void main() { test('', () { customContainer = document.body!.append(DivElement()..id = 'custom-container'); final renderedResult = - rtl.render(react.div({'id': 'root'}, 'oh hai') as ReactElement, container: customContainer); + rtl.render(react.div({'id': 'root'}, 'oh hai'), container: customContainer); expect(renderedResult.container, same(customContainer)); expect(document.body!.contains(renderedResult.container), isTrue); expect(renderedResult.container.childNodes, hasLength(1)); @@ -173,7 +173,7 @@ void main() { test('', () { customContainer = document.body!.append(DivElement()..id = 'custom-container'); - view = rtl.render(react.div({'id': 'root'}, 'oh hai') as ReactElement, + view = rtl.render(react.div({'id': 'root'}, 'oh hai'), container: customContainer, autoTearDown: false); }); }); @@ -214,7 +214,7 @@ void main() { test('for dom elements', () { final printCalls = recordPrintCalls( - () => rtl.render(react.input({'value': 'abc'}) as ReactElement), + () => rtl.render(react.input({'value': 'abc'})), ); expect( printCalls, diff --git a/test/unit/user_event/clear_test.dart b/test/unit/user_event/clear_test.dart index 206333ab..cc3e8b36 100644 --- a/test/unit/user_event/clear_test.dart +++ b/test/unit/user_event/clear_test.dart @@ -15,7 +15,6 @@ import 'dart:html'; import 'package:react/react.dart' as react; -import 'package:react/react_client.dart' show ReactElement; import 'package:react_testing_library/matchers.dart'; import 'package:react_testing_library/react_testing_library.dart' as rtl; import 'package:react_testing_library/user_event.dart'; @@ -28,7 +27,7 @@ void main() { test('on an InputElement', () { final view = rtl.render(react.input({ 'defaultValue': 'Hello, World!', - }) as ReactElement); + })); final input = view.getByRole('textbox') as InputElement; UserEvent.clear(input); expect(input, hasValue('')); @@ -37,7 +36,7 @@ void main() { test('on an TextAreaElement', () { final view = rtl.render(react.textarea({ 'defaultValue': 'Hello, World!', - }) as ReactElement); + })); final textarea = view.getByRole('textbox') as TextAreaElement; expect(textarea, hasValue('Hello, World!'), reason: 'sanity check'); UserEvent.clear(textarea); diff --git a/test/unit/user_event/click_test.dart b/test/unit/user_event/click_test.dart index f155048f..11dd1bdf 100644 --- a/test/unit/user_event/click_test.dart +++ b/test/unit/user_event/click_test.dart @@ -15,7 +15,6 @@ import 'dart:html'; import 'package:react/react.dart' as react; -import 'package:react/react_client.dart' show ReactElement; import 'package:react_testing_library/react_testing_library.dart' as rtl; import 'package:react_testing_library/user_event.dart'; import 'package:test/test.dart'; @@ -41,7 +40,7 @@ void main() { 'onMouseOver': (_) => hoverEventCount++, }, 'oh hai'); - view = rtl.render(elementToRender as ReactElement); + view = rtl.render(elementToRender); }); group('UserEvent.click', () { @@ -103,7 +102,7 @@ void main() { 'onClick': (_) { wasClicked = true; } - }, 'oh hai') as ReactElement); + }, 'oh hai')); UserEvent.click( view.getByRole('button'), @@ -162,7 +161,7 @@ void main() { 'onDoubleClick': (_) { wasClicked = true; } - }, 'oh hai') as ReactElement); + }, 'oh hai')); UserEvent.dblClick( view.getByRole('button'), diff --git a/test/unit/user_event/hover_test.dart b/test/unit/user_event/hover_test.dart index 47091a55..1eaca62f 100644 --- a/test/unit/user_event/hover_test.dart +++ b/test/unit/user_event/hover_test.dart @@ -16,7 +16,7 @@ import 'dart:html'; import 'package:react/hooks.dart' show useState; import 'package:react/react.dart' as react; -import 'package:react/react_client.dart' show ReactDartFunctionComponentFactoryProxy, ReactElement; +import 'package:react/react_client.dart' show ReactDartFunctionComponentFactoryProxy; import 'package:react_testing_library/matchers.dart'; import 'package:react_testing_library/react_testing_library.dart' as rtl; import 'package:react_testing_library/user_event.dart'; @@ -33,7 +33,7 @@ void main() { calls = []; view = rtl.render(react.div({}, [ HoverTestComponent({'calls': calls}) - ]) as ReactElement); + ])); // Sanity check. expect(view.queryByText('Hello!'), isNull); }); @@ -77,7 +77,7 @@ void main() { 'style': {'pointerEvents': 'none'} }, [ HoverTestComponent({'calls': calls}) - ]) as ReactElement); + ])); UserEvent.hover(view.getByRole('button'), skipPointerEventsCheck: true); expect(view.getByText('Hello!'), isInTheDocument); diff --git a/test/unit/user_event/paste_test.dart b/test/unit/user_event/paste_test.dart index e0285ac4..818b7c15 100644 --- a/test/unit/user_event/paste_test.dart +++ b/test/unit/user_event/paste_test.dart @@ -15,7 +15,6 @@ import 'dart:html'; import 'package:react/react.dart' as react; -import 'package:react/react_client.dart' show ReactElement; import 'package:react_testing_library/matchers.dart'; import 'package:react_testing_library/react_testing_library.dart' as rtl; import 'package:react_testing_library/user_event.dart'; @@ -47,7 +46,7 @@ void main() { }, }); - view = rtl.render(elementToRender as ReactElement); + view = rtl.render(elementToRender); input = view.getByRole('textbox'); expect(input, hasValue('')); }); @@ -74,7 +73,7 @@ void main() { 'defaultValue': 'this is a bad example', }); - view = rtl.render(elementToRender as ReactElement); + view = rtl.render(elementToRender); input = view.getByRole('textbox'); expect(input, hasValue('this is a bad example')); }); diff --git a/test/unit/user_event/select_options_test.dart b/test/unit/user_event/select_options_test.dart index 796f3890..343f5dbb 100644 --- a/test/unit/user_event/select_options_test.dart +++ b/test/unit/user_event/select_options_test.dart @@ -15,7 +15,6 @@ import 'dart:html'; import 'package:react/react.dart' as react; -import 'package:react/react_client.dart' show ReactElement; import 'package:react_testing_library/react_testing_library.dart' as rtl; import 'package:react_testing_library/user_event.dart'; import 'package:test/test.dart'; @@ -43,7 +42,7 @@ void main() { react.option({'value': '1'}, 'A'), react.option({'value': '2'}, 'B'), react.option({'value': '3'}, 'C'), - ]) as ReactElement); + ])); select = view.getByRole(isMultiSelect ? 'listbox' : 'combobox'); @@ -106,7 +105,7 @@ void main() { react.option({'value': '1'}, 'A'), react.option({'value': '2'}, 'B'), react.option({'value': '3'}, 'C'), - ]) as ReactElement); + ])); UserEvent.selectOptions(select, isMultiSelect ? ['1', '3'] : ['3'], skipPointerEventsCheck: true); @@ -151,7 +150,7 @@ void main() { react.option({'value': '1'}, 'A'), react.option({'value': '2'}, 'B'), react.option({'value': '3'}, 'C'), - ]) as ReactElement); + ])); select = view.getByRole('listbox'); @@ -211,7 +210,7 @@ void main() { react.option({'value': '1'}, 'A'), react.option({'value': '2'}, 'B'), react.option({'value': '3'}, 'C'), - ]) as ReactElement); + ])); UserEvent.deselectOptions( select, diff --git a/test/unit/user_event/special_chars_test.dart b/test/unit/user_event/special_chars_test.dart index 83c0c688..cb06d46a 100644 --- a/test/unit/user_event/special_chars_test.dart +++ b/test/unit/user_event/special_chars_test.dart @@ -15,7 +15,6 @@ import 'dart:html'; import 'package:react/react.dart' as react; -import 'package:react/react_client.dart' show ReactElement; import 'package:react_testing_library/react_testing_library.dart' as rtl; import 'package:react_testing_library/matchers.dart'; import 'package:react_testing_library/user_event.dart'; @@ -39,7 +38,7 @@ void main() { 'defaultValue': 'hello\n\nthere!', 'onKeyDown': (e) => keyDownCalls.add((e as react.SyntheticKeyboardEvent).key), }), - ]) as ReactElement); + ])); input = view.getAllByRole('textbox').first as InputElement; textArea = view.getAllByRole('textbox')[1] as TextAreaElement; diff --git a/test/unit/user_event/tab_test.dart b/test/unit/user_event/tab_test.dart index d89baaef..5fe617b4 100644 --- a/test/unit/user_event/tab_test.dart +++ b/test/unit/user_event/tab_test.dart @@ -15,7 +15,6 @@ import 'dart:html'; import 'package:react/react.dart' as react; -import 'package:react/react_client.dart' show ReactElement; import 'package:react_testing_library/matchers.dart'; import 'package:react_testing_library/react_testing_library.dart' as rtl; import 'package:react_testing_library/user_event.dart'; @@ -41,7 +40,7 @@ void main() { ]), ]); - view = rtl.render(elementToRender as ReactElement); + view = rtl.render(elementToRender); inputs = view.getAllByRole('textbox'); expect(inputs, hasLength(3), reason: 'sanity check'); }); diff --git a/test/unit/user_event/type_test.dart b/test/unit/user_event/type_test.dart index 2517aa28..8f3a7788 100644 --- a/test/unit/user_event/type_test.dart +++ b/test/unit/user_event/type_test.dart @@ -16,7 +16,6 @@ import 'dart:async'; import 'dart:html'; import 'package:react/react.dart' as react; -import 'package:react/react_client.dart' show ReactElement; import 'package:react_testing_library/react_testing_library.dart' as rtl; import 'package:react_testing_library/matchers.dart'; import 'package:react_testing_library/user_event.dart'; @@ -110,7 +109,7 @@ void _typeTestHelper({bool hasDelay = false, bool isTextArea = false}) { 'id': 'root', 'onClick': (_) => clickEventCount++, 'onKeyUp': (e) => keyUpCalls.add((e as react.SyntheticKeyboardEvent).key), - }) as ReactElement); + })); element = view.getByRole('textbox'); expect(element, hasValue(''), reason: 'sanity check'); @@ -210,7 +209,7 @@ void _typeTestHelper({bool hasDelay = false, bool isTextArea = false}) { final view = rtl.render((isTextArea ? react.textarea : react.input)({ defaultTestIdKey: 'event-handle-error-tester', 'onKeyUp': (e) => throw ExceptionForTesting('ow'), - }) as ReactElement); + })); expect( () async { @@ -243,7 +242,7 @@ void _typeTestHelper({bool hasDelay = false, bool isTextArea = false}) { 'onClick': (_) => clickEventCount++, 'onKeyUp': (e) => keyUpCalls.add((e as react.SyntheticKeyboardEvent).key), 'defaultValue': 'this is a bad example', - }) as ReactElement); + })); element = view.getByRole('textbox'); expect(element, hasValue('this is a bad example'), reason: 'sanity check'); @@ -332,7 +331,7 @@ void _keyboardTestHelper({bool hasDelay = false}) { }, }); - view = rtl.render(elementToRender as ReactElement); + view = rtl.render(elementToRender); input = view.getByRole('textbox'); expect(input, hasValue('')); }); diff --git a/test/unit/user_event/upload_test.dart b/test/unit/user_event/upload_test.dart index ac242b9a..5352468a 100644 --- a/test/unit/user_event/upload_test.dart +++ b/test/unit/user_event/upload_test.dart @@ -15,7 +15,6 @@ import 'dart:html'; import 'package:react/react.dart' as react; -import 'package:react/react_client.dart' show ReactElement; import 'package:react_testing_library/react_testing_library.dart' as rtl; import 'package:react_testing_library/user_event.dart'; import 'package:test/test.dart'; @@ -58,7 +57,7 @@ void main() { }), ]); - final view = rtl.render(elementToRender as ReactElement); + final view = rtl.render(elementToRender); input = view.getByLabelText('Upload file:'); label = view.getByText('Upload file:'); expect(input.files, hasLength(0), reason: 'sanity check'); diff --git a/test/unit/util/event_handler_error.dart b/test/unit/util/event_handler_error.dart index d3ecfd13..389e8696 100644 --- a/test/unit/util/event_handler_error.dart +++ b/test/unit/util/event_handler_error.dart @@ -15,7 +15,6 @@ import 'dart:html'; import 'package:react/react.dart' as react; -import 'package:react/react_client.dart' show ReactElement; import 'package:react_testing_library/react_testing_library.dart' as rtl; import 'package:test/test.dart'; @@ -38,14 +37,14 @@ void testEventHandlerErrors( group('will rethrow', () { test('event handler error', () { - final view = rtl.render(buildTargetElement() as ReactElement); + final view = rtl.render(buildTargetElement()); expect(() => userEventTrigger(view.getByTestId(targetTestId)), throwsA(isA())); }); test('multiple event handler errors as an exception', () { final toRender = react.div(buildEventHandlers(), buildTargetElement()); - final view = rtl.render(toRender as ReactElement); + final view = rtl.render(toRender); expect( () => userEventTrigger(view.getByTestId(targetTestId)), diff --git a/test/unit/util/rendering.dart b/test/unit/util/rendering.dart index 39b56229..e11a8f65 100644 --- a/test/unit/util/rendering.dart +++ b/test/unit/util/rendering.dart @@ -59,7 +59,7 @@ ReactElement elementsForQuerying(String uniqueName, {bool? renderMultipleElsMatc {}, react.button({'type': 'button'}, _uniqueName), ), - ) as ReactElement; + ); } renderMultipleElsMatchingQuery ??= false; @@ -69,7 +69,7 @@ ReactElement elementsForQuerying(String uniqueName, {bool? renderMultipleElsMatc {}, renderEls(uniqueName), renderEls('2$uniqueName'), - ) as ReactElement; + ); } return renderEls(uniqueName); From 976b962c6d00236b1d61a4a742c2093399e72f44 Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Mon, 13 Nov 2023 13:35:09 -0700 Subject: [PATCH 15/31] Change CI to 2.19.6 --- .github/workflows/dart_ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dart_ci.yml b/.github/workflows/dart_ci.yml index 71fc11dc..51f3d993 100644 --- a/.github/workflows/dart_ci.yml +++ b/.github/workflows/dart_ci.yml @@ -15,7 +15,7 @@ jobs: strategy: fail-fast: false matrix: - sdk: [ 2.18.7, 2.19.4 ] + sdk: [ 2.18.7, 2.19.6 ] steps: - uses: actions/checkout@v2 - uses: dart-lang/setup-dart@v1 From 8f45e913967fcd98f21dfb658ddcfc4689c46b2e Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Mon, 13 Nov 2023 14:15:44 -0700 Subject: [PATCH 16/31] Fix warnings --- lib/src/dom/async/wait_for.dart | 2 +- lib/src/user_event/user_event.dart | 4 ++-- test/unit/console_log_utils_test.dart | 10 +++++----- test/unit/react/render_test.dart | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/src/dom/async/wait_for.dart b/lib/src/dom/async/wait_for.dart index cb4f8bef..78a1ec5c 100644 --- a/lib/src/dom/async/wait_for.dart +++ b/lib/src/dom/async/wait_for.dart @@ -104,7 +104,7 @@ Future waitFor( final result = expectation(); if (result is Future) { isPending = true; - (result as Future) + (result! as Future) .then((resolvedValue) => onDone(null, resolvedValue as T), onError: (e) => lastError = e) .whenComplete(() => isPending = false); } else { diff --git a/lib/src/user_event/user_event.dart b/lib/src/user_event/user_event.dart index e24003ce..7c8f69fd 100644 --- a/lib/src/user_event/user_event.dart +++ b/lib/src/user_event/user_event.dart @@ -770,8 +770,8 @@ abstract class UserEvent { // Convert the `element.files` because the JS `upload` sets it equal to a // map with with an `item` method to access files. if (element is LabelElement && element.control is FileUploadInputElement) { - (element.control as FileUploadInputElement).files = - _unjsifyFileList((element.control as FileUploadInputElement).files); + (element.control! as FileUploadInputElement).files = + _unjsifyFileList((element.control! as FileUploadInputElement).files); } else if (element is FileUploadInputElement) { element.files = _unjsifyFileList(element.files); } diff --git a/test/unit/console_log_utils_test.dart b/test/unit/console_log_utils_test.dart index 9de1363f..76be9460 100644 --- a/test/unit/console_log_utils_test.dart +++ b/test/unit/console_log_utils_test.dart @@ -515,9 +515,9 @@ class _SampleComponent extends react.Component2 { }; @override - Map> get propTypes => { + Map> get propTypes => { 'shouldNeverBeNull': (props, info) { - if ((props as Map)['shouldNeverBeNull'] == null) { + if (props['shouldNeverBeNull'] == null) { return ArgumentError('${info.propName} is necessary.'); } @@ -532,7 +532,7 @@ class _SampleComponent extends react.Component2 { return null; }, 'shouldAlwaysBeFalse': (props, info) { - if ((props as Map)['shouldAlwaysBeFalse'] as bool) { + if (props['shouldAlwaysBeFalse'] as bool) { return ArgumentError('${info.propName} should never equal true.'); } @@ -585,9 +585,9 @@ final Sample = react.registerComponent2(() => _SampleComponent()); class _Sample2Component extends react.Component2 { @override - Map> get propTypes => { + Map> get propTypes => { 'shouldNeverBeNull': (props, info) { - if ((props as Map)['shouldNeverBeNull'] == null) { + if (props['shouldNeverBeNull'] == null) { return ArgumentError('shouldNeverBeNull is required.'); } diff --git a/test/unit/react/render_test.dart b/test/unit/react/render_test.dart index 394d2092..b623b544 100644 --- a/test/unit/react/render_test.dart +++ b/test/unit/react/render_test.dart @@ -260,9 +260,9 @@ final PortalComponent = react.registerComponent2(() => _PortalComponent()); class _TestComponent extends react.Component2 { @override - Map> get propTypes => { + Map> get propTypes => { 'name': (props, info) { - final propValue = (props as Map)[info.propName] as String; + final propValue = props[info.propName] as String; if (propValue.length > 20) { return ArgumentError('($propValue) is too long. $propValue has a max length of 20 characters.'); } From 25f3e5ced45350018f51a890fd3f035cc5d3d058 Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Mon, 13 Nov 2023 14:16:19 -0700 Subject: [PATCH 17/31] Format --- test/unit/dom/matchers/contains_element_test.dart | 3 +-- test/unit/dom/matchers/has_text_content_test.dart | 3 +-- test/unit/dom/matchers/is_disabled_test.dart | 3 +-- test/unit/dom/matchers/is_empty_dom_element_test.dart | 3 +-- test/unit/react/render_test.dart | 6 ++---- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/test/unit/dom/matchers/contains_element_test.dart b/test/unit/dom/matchers/contains_element_test.dart index 4864961f..a6740fef 100644 --- a/test/unit/dom/matchers/contains_element_test.dart +++ b/test/unit/dom/matchers/contains_element_test.dart @@ -50,8 +50,7 @@ void main() { }); test('the matched item does not have a matching descendant', () { - final view = render( - react.span({defaultTestIdKey: 'ancestor'}, react.span({defaultTestIdKey: 'descendant'}))); + final view = render(react.span({defaultTestIdKey: 'ancestor'}, react.span({defaultTestIdKey: 'descendant'}))); final ancestor = view.getByTestId('ancestor'); final descendant = view.getByTestId('descendant'); shouldFail(descendant, containsElement(ancestor), contains('Which: does not contain $ancestor.')); diff --git a/test/unit/dom/matchers/has_text_content_test.dart b/test/unit/dom/matchers/has_text_content_test.dart index 5af7e418..76ad28b9 100644 --- a/test/unit/dom/matchers/has_text_content_test.dart +++ b/test/unit/dom/matchers/has_text_content_test.dart @@ -28,8 +28,7 @@ void main() { late Element rootElement; setUp(() { - final view = render( - react.span({defaultTestIdKey: 'root'}, 'The quick brown fox jumps over the (lazy) dog')); + final view = render(react.span({defaultTestIdKey: 'root'}, 'The quick brown fox jumps over the (lazy) dog')); rootElement = view.getByTestId('root'); }); diff --git a/test/unit/dom/matchers/is_disabled_test.dart b/test/unit/dom/matchers/is_disabled_test.dart index c56912d4..e0c33922 100644 --- a/test/unit/dom/matchers/is_disabled_test.dart +++ b/test/unit/dom/matchers/is_disabled_test.dart @@ -28,8 +28,7 @@ void main() { group('passes when provided a valid Element that can be disabled', () { test('is disabled', () { shouldPass(InputElement()..disabled = true, isDisabled); - final view = render( - react.form({'disabled': true, defaultTestIdKey: 'form'}, react.button({'type': 'submit'}))); + final view = render(react.form({'disabled': true, defaultTestIdKey: 'form'}, react.button({'type': 'submit'}))); shouldPass(view.getByTestId('form'), isDisabled); }); diff --git a/test/unit/dom/matchers/is_empty_dom_element_test.dart b/test/unit/dom/matchers/is_empty_dom_element_test.dart index 9f414770..1134a31c 100644 --- a/test/unit/dom/matchers/is_empty_dom_element_test.dart +++ b/test/unit/dom/matchers/is_empty_dom_element_test.dart @@ -36,8 +36,7 @@ void main() { }); test('the matched item has empty children', () { - final view = render( - react.span({defaultTestIdKey: 'not-empty'}, react.span({defaultTestIdKey: 'empty'}))); + final view = render(react.span({defaultTestIdKey: 'not-empty'}, react.span({defaultTestIdKey: 'empty'}))); shouldFail(view.getByTestId('not-empty'), isEmptyDomElement, contains('Which: is not an empty DOM Element.')); }); diff --git a/test/unit/react/render_test.dart b/test/unit/react/render_test.dart index b623b544..11b92c51 100644 --- a/test/unit/react/render_test.dart +++ b/test/unit/react/render_test.dart @@ -148,8 +148,7 @@ void main() { test('', () { customContainer = document.body!.append(DivElement()..id = 'custom-container'); - final renderedResult = - rtl.render(react.div({'id': 'root'}, 'oh hai'), container: customContainer); + final renderedResult = rtl.render(react.div({'id': 'root'}, 'oh hai'), container: customContainer); expect(renderedResult.container, same(customContainer)); expect(document.body!.contains(renderedResult.container), isTrue); expect(renderedResult.container.childNodes, hasLength(1)); @@ -173,8 +172,7 @@ void main() { test('', () { customContainer = document.body!.append(DivElement()..id = 'custom-container'); - view = rtl.render(react.div({'id': 'root'}, 'oh hai'), - container: customContainer, autoTearDown: false); + view = rtl.render(react.div({'id': 'root'}, 'oh hai'), container: customContainer, autoTearDown: false); }); }); }); From e552d8516ef598f50e04956534448589d49338f3 Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Mon, 13 Nov 2023 14:24:17 -0700 Subject: [PATCH 18/31] Fix diff --- .github/workflows/build_and_deploy_docs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_deploy_docs.yml b/.github/workflows/build_and_deploy_docs.yml index f17895f5..c3883e6c 100644 --- a/.github/workflows/build_and_deploy_docs.yml +++ b/.github/workflows/build_and_deploy_docs.yml @@ -50,4 +50,4 @@ jobs: artifact_name: dartdoc if: ${{ steps.build-docs.outcome == 'success' && steps.archive-dartdoc-artifact.outcome == 'success' && github.event_name == 'push' }} - + From 417a7546167d0b2032c8d5d929410d59064b9c0e Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Mon, 13 Nov 2023 14:25:18 -0700 Subject: [PATCH 19/31] Remove 2.18 CI check --- .github/workflows/build_and_deploy_docs.yml | 6 ++---- .github/workflows/dart_ci.yml | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build_and_deploy_docs.yml b/.github/workflows/build_and_deploy_docs.yml index c3883e6c..92bb3cb7 100644 --- a/.github/workflows/build_and_deploy_docs.yml +++ b/.github/workflows/build_and_deploy_docs.yml @@ -19,7 +19,7 @@ jobs: strategy: fail-fast: false matrix: - sdk: [ 2.18.7 ] + sdk: [ 2.19.6 ] steps: - uses: actions/checkout@v3 - uses: dart-lang/setup-dart@v1 @@ -32,7 +32,7 @@ jobs: - id: build-docs name: Build Docs run: dart pub get && dart doc . - if: ${{ matrix.sdk == '2.18.7' }} + if: ${{ matrix.sdk == '2.19.6' }} # Upload the artifact as required by actions/deploy-pages - name: Archive Dartdoc Artifact @@ -49,5 +49,3 @@ jobs: with: artifact_name: dartdoc if: ${{ steps.build-docs.outcome == 'success' && steps.archive-dartdoc-artifact.outcome == 'success' && github.event_name == 'push' }} - - diff --git a/.github/workflows/dart_ci.yml b/.github/workflows/dart_ci.yml index 51f3d993..90a70ed1 100644 --- a/.github/workflows/dart_ci.yml +++ b/.github/workflows/dart_ci.yml @@ -15,7 +15,7 @@ jobs: strategy: fail-fast: false matrix: - sdk: [ 2.18.7, 2.19.6 ] + sdk: [ 2.19.6 ] steps: - uses: actions/checkout@v2 - uses: dart-lang/setup-dart@v1 From e7426caa97b71ba8358363b7ff058972612d9a93 Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Mon, 13 Nov 2023 14:39:56 -0700 Subject: [PATCH 20/31] Fix casting --- lib/src/dom/async/wait_for.dart | 2 +- lib/src/user_event/user_event.dart | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/src/dom/async/wait_for.dart b/lib/src/dom/async/wait_for.dart index 78a1ec5c..e0fa50d0 100644 --- a/lib/src/dom/async/wait_for.dart +++ b/lib/src/dom/async/wait_for.dart @@ -104,7 +104,7 @@ Future waitFor( final result = expectation(); if (result is Future) { isPending = true; - (result! as Future) + result .then((resolvedValue) => onDone(null, resolvedValue as T), onError: (e) => lastError = e) .whenComplete(() => isPending = false); } else { diff --git a/lib/src/user_event/user_event.dart b/lib/src/user_event/user_event.dart index 7c8f69fd..c57e14a7 100644 --- a/lib/src/user_event/user_event.dart +++ b/lib/src/user_event/user_event.dart @@ -769,9 +769,9 @@ abstract class UserEvent { // Convert the `element.files` because the JS `upload` sets it equal to a // map with with an `item` method to access files. - if (element is LabelElement && element.control is FileUploadInputElement) { - (element.control! as FileUploadInputElement).files = - _unjsifyFileList((element.control! as FileUploadInputElement).files); + final control = element is LabelElement ? element.control : null; + if (control is InputElement) { + control.files = _unjsifyFileList(control.files); } else if (element is FileUploadInputElement) { element.files = _unjsifyFileList(element.files); } From 7b76f367c9258f3d089cee244fc21f49e7ba7aac Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Mon, 13 Nov 2023 14:50:54 -0700 Subject: [PATCH 21/31] Fix Future casting --- lib/src/dom/async/wait_for.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/dom/async/wait_for.dart b/lib/src/dom/async/wait_for.dart index e0fa50d0..78a1ec5c 100644 --- a/lib/src/dom/async/wait_for.dart +++ b/lib/src/dom/async/wait_for.dart @@ -104,7 +104,7 @@ Future waitFor( final result = expectation(); if (result is Future) { isPending = true; - result + (result! as Future) .then((resolvedValue) => onDone(null, resolvedValue as T), onError: (e) => lastError = e) .whenComplete(() => isPending = false); } else { From fb14bc222c2998a61558436af80370a9d2c2b727 Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Wed, 15 Nov 2023 11:43:34 -0700 Subject: [PATCH 22/31] Make screen.container non-nullable --- lib/src/dom/accessibility_helpers.dart | 14 ++++++++------ lib/src/dom/queries/by_alt_text.dart | 8 ++++---- lib/src/dom/queries/by_display_value.dart | 8 ++++---- lib/src/dom/queries/by_label_text.dart | 8 ++++---- lib/src/dom/queries/by_placeholder_text.dart | 8 ++++---- lib/src/dom/queries/by_role.dart | 8 ++++---- lib/src/dom/queries/by_testid.dart | 8 ++++---- lib/src/dom/queries/by_text.dart | 8 ++++---- lib/src/dom/queries/by_title.dart | 8 ++++---- lib/src/dom/queries/interface.dart | 2 +- lib/src/dom/scoped_queries.dart | 2 +- lib/src/dom/within.dart | 4 ++-- test/unit/dom/accessibility_helpers_test.dart | 2 +- .../unit/dom/matchers/is_in_the_document_test.dart | 2 +- test/unit/dom/within_test.dart | 2 +- test/unit/user_event/hover_test.dart | 3 +++ 16 files changed, 50 insertions(+), 45 deletions(-) diff --git a/lib/src/dom/accessibility_helpers.dart b/lib/src/dom/accessibility_helpers.dart index a3fc34d6..c95ba6f7 100644 --- a/lib/src/dom/accessibility_helpers.dart +++ b/lib/src/dom/accessibility_helpers.dart @@ -32,8 +32,9 @@ import 'package:react_testing_library/src/util/console_log_utils.dart'; /// > Learn more: /// /// {@category Accessibility} -Map getRoles(Node? container, {bool hidden = false}) => - Map.from(JsBackedMap.fromJs(_getRoles(container, jsifyAndAllowInterop({'hidden': hidden}) as JsMap))); +Map getRoles(Node container, {bool hidden = false}) { + return Map.from(JsBackedMap.fromJs(_getRoles(container, jsifyAndAllowInterop({'hidden': hidden}) as JsMap))); +} /// Prints a list of all the implicit ARIA roles within [container], each role containing a list of all of the /// nodes which match that role. @@ -45,12 +46,13 @@ Map getRoles(Node? container, {bool hidden = false}) => /// > Learn more: /// /// {@category Accessibility} -void logRoles(Node? container, {bool hidden = false}) => - printConsoleLogs(() => _logRoles(container, jsifyAndAllowInterop({'hidden': hidden}) as JsMap)); +void logRoles(Node container, {bool hidden = false}) { + printConsoleLogs(() => _logRoles(container, jsifyAndAllowInterop({'hidden': hidden}) as JsMap)); +} @JS('rtl.getRoles') external JsMap _getRoles( - Node? container, + Node container, JsMap options, ); @@ -68,6 +70,6 @@ external bool isInaccessible(Element element); @JS('rtl.logRoles') external JsMap _logRoles( - Node? dom, + Node dom, JsMap options, ); diff --git a/lib/src/dom/queries/by_alt_text.dart b/lib/src/dom/queries/by_alt_text.dart index d872b02a..90974731 100644 --- a/lib/src/dom/queries/by_alt_text.dart +++ b/lib/src/dom/queries/by_alt_text.dart @@ -315,28 +315,28 @@ mixin ByAltTextQueries on IQueries { @JS('rtl.getByAltText') external Element _jsGetByAltText( - Node? container, + Node container, /*TextMatch*/ dynamic text, [ MatcherOptions? options, ]); @JS('rtl.getAllByAltText') external List< /*Element*/ dynamic> _jsGetAllByAltText( - Node? container, + Node container, /*TextMatch*/ dynamic text, [ MatcherOptions? options, ]); @JS('rtl.queryByAltText') external Element? _jsQueryByAltText( - Node? container, + Node container, /*TextMatch*/ dynamic text, [ MatcherOptions? options, ]); @JS('rtl.queryAllByAltText') external List< /*Element*/ dynamic> _jsQueryAllByAltText( - Node? container, + Node container, /*TextMatch*/ dynamic text, [ MatcherOptions? options, ]); diff --git a/lib/src/dom/queries/by_display_value.dart b/lib/src/dom/queries/by_display_value.dart index ab65721c..cfad4b12 100644 --- a/lib/src/dom/queries/by_display_value.dart +++ b/lib/src/dom/queries/by_display_value.dart @@ -340,28 +340,28 @@ mixin ByDisplayValueQueries on IQueries { @JS('rtl.getByDisplayValue') external Element _jsGetByDisplayValue( - Node? container, + Node container, /*TextMatch*/ dynamic value, [ MatcherOptions? options, ]); @JS('rtl.getAllByDisplayValue') external List< /*Element*/ dynamic> _jsGetAllByDisplayValue( - Node? container, + Node container, /*TextMatch*/ dynamic value, [ MatcherOptions? options, ]); @JS('rtl.queryByDisplayValue') external Element? _jsQueryByDisplayValue( - Node? container, + Node container, /*TextMatch*/ dynamic value, [ MatcherOptions? options, ]); @JS('rtl.queryAllByDisplayValue') external List< /*Element*/ dynamic> _jsQueryAllByDisplayValue( - Node? container, + Node container, /*TextMatch*/ dynamic value, [ MatcherOptions? options, ]); diff --git a/lib/src/dom/queries/by_label_text.dart b/lib/src/dom/queries/by_label_text.dart index 34b76582..8995c2ac 100644 --- a/lib/src/dom/queries/by_label_text.dart +++ b/lib/src/dom/queries/by_label_text.dart @@ -334,28 +334,28 @@ mixin ByLabelTextQueries on IQueries { @JS('rtl.getByLabelText') external Element _jsGetByLabelText( - Node? container, + Node container, /*TextMatch*/ dynamic text, [ MatcherOptions? options, ]); @JS('rtl.getAllByLabelText') external List< /*Element*/ dynamic> _jsGetAllByLabelText( - Node? container, + Node container, /*TextMatch*/ dynamic text, [ MatcherOptions? options, ]); @JS('rtl.queryByLabelText') external Element? _jsQueryByLabelText( - Node? container, + Node container, /*TextMatch*/ dynamic text, [ MatcherOptions? options, ]); @JS('rtl.queryAllByLabelText') external List< /*Element*/ dynamic> _jsQueryAllByLabelText( - Node? container, + Node container, /*TextMatch*/ dynamic text, [ MatcherOptions? options, ]); diff --git a/lib/src/dom/queries/by_placeholder_text.dart b/lib/src/dom/queries/by_placeholder_text.dart index 33fe8f0d..d2738f50 100644 --- a/lib/src/dom/queries/by_placeholder_text.dart +++ b/lib/src/dom/queries/by_placeholder_text.dart @@ -309,28 +309,28 @@ mixin ByPlaceholderTextQueries on IQueries { @JS('rtl.getByPlaceholderText') external Element _jsGetByPlaceholderText( - Node? container, + Node container, /*TextMatch*/ dynamic text, [ MatcherOptions? options, ]); @JS('rtl.getAllByPlaceholderText') external List< /*Element*/ dynamic> _jsGetAllByPlaceholderText( - Node? container, + Node container, /*TextMatch*/ dynamic text, [ MatcherOptions? options, ]); @JS('rtl.queryByPlaceholderText') external Element? _jsQueryByPlaceholderText( - Node? container, + Node container, /*TextMatch*/ dynamic text, [ MatcherOptions? options, ]); @JS('rtl.queryAllByPlaceholderText') external List< /*Element*/ dynamic> _jsQueryAllByPlaceholderText( - Node? container, + Node container, /*TextMatch*/ dynamic text, [ MatcherOptions? options, ]); diff --git a/lib/src/dom/queries/by_role.dart b/lib/src/dom/queries/by_role.dart index deb0f226..08cfe6f3 100644 --- a/lib/src/dom/queries/by_role.dart +++ b/lib/src/dom/queries/by_role.dart @@ -483,28 +483,28 @@ mixin ByRoleQueries on IQueries { @JS('rtl.getByRole') external Element _jsGetByRole( - Node? container, + Node container, /*TextMatch*/ dynamic role, [ ByRoleOptions? options, ]); @JS('rtl.getAllByRole') external List< /*Element*/ dynamic> _jsGetAllByRole( - Node? container, + Node container, /*TextMatch*/ dynamic role, [ ByRoleOptions? options, ]); @JS('rtl.queryByRole') external Element? _jsQueryByRole( - Node? container, + Node container, /*TextMatch*/ dynamic role, [ ByRoleOptions? options, ]); @JS('rtl.queryAllByRole') external List< /*Element*/ dynamic> _jsQueryAllByRole( - Node? container, + Node container, /*TextMatch*/ dynamic role, [ ByRoleOptions? options, ]); diff --git a/lib/src/dom/queries/by_testid.dart b/lib/src/dom/queries/by_testid.dart index 91fcedc2..f023c695 100644 --- a/lib/src/dom/queries/by_testid.dart +++ b/lib/src/dom/queries/by_testid.dart @@ -409,28 +409,28 @@ mixin ByTestIdQueries on IQueries { @JS('rtl.getByTestId') external Element _jsGetByTestId( - Node? container, + Node container, /*TextMatch*/ dynamic testId, [ MatcherOptions? options, ]); @JS('rtl.getAllByTestId') external List< /*Element*/ dynamic> _jsGetAllByTestId( - Node? container, + Node container, /*TextMatch*/ dynamic testId, [ MatcherOptions? options, ]); @JS('rtl.queryByTestId') external Element? _jsQueryByTestId( - Node? container, + Node container, /*TextMatch*/ dynamic testId, [ MatcherOptions? options, ]); @JS('rtl.queryAllByTestId') external List< /*Element*/ dynamic> _jsQueryAllByTestId( - Node? container, + Node container, /*TextMatch*/ dynamic testId, [ MatcherOptions? options, ]); diff --git a/lib/src/dom/queries/by_text.dart b/lib/src/dom/queries/by_text.dart index 008a7416..78a2f545 100644 --- a/lib/src/dom/queries/by_text.dart +++ b/lib/src/dom/queries/by_text.dart @@ -338,28 +338,28 @@ mixin ByTextQueries on IQueries { @JS('rtl.getByText') external Element _jsGetByText( - Node? container, + Node container, /*TextMatch*/ dynamic text, [ MatcherOptions? options, ]); @JS('rtl.getAllByText') external List< /*Element*/ dynamic> _jsGetAllByText( - Node? container, + Node container, /*TextMatch*/ dynamic text, [ MatcherOptions? options, ]); @JS('rtl.queryByText') external Element? _jsQueryByText( - Node? container, + Node container, /*TextMatch*/ dynamic text, [ MatcherOptions? options, ]); @JS('rtl.queryAllByText') external List< /*Element*/ dynamic> _jsQueryAllByText( - Node? container, + Node container, /*TextMatch*/ dynamic text, [ MatcherOptions? options, ]); diff --git a/lib/src/dom/queries/by_title.dart b/lib/src/dom/queries/by_title.dart index 0538bb2c..c6064abd 100644 --- a/lib/src/dom/queries/by_title.dart +++ b/lib/src/dom/queries/by_title.dart @@ -318,28 +318,28 @@ mixin ByTitleQueries on IQueries { @JS('rtl.getByTitle') external Element _jsGetByTitle( - Node? container, + Node container, /*TextMatch*/ dynamic title, [ MatcherOptions? options, ]); @JS('rtl.getAllByTitle') external List< /*Element*/ dynamic> _jsGetAllByTitle( - Node? container, + Node container, /*TextMatch*/ dynamic title, [ MatcherOptions? options, ]); @JS('rtl.queryByTitle') external Element? _jsQueryByTitle( - Node? container, + Node container, /*TextMatch*/ dynamic title, [ MatcherOptions? options, ]); @JS('rtl.queryAllByTitle') external List< /*Element*/ dynamic> _jsQueryAllByTitle( - Node? container, + Node container, /*TextMatch*/ dynamic title, [ MatcherOptions? options, ]); diff --git a/lib/src/dom/queries/interface.dart b/lib/src/dom/queries/interface.dart index 28815647..5cde462c 100644 --- a/lib/src/dom/queries/interface.dart +++ b/lib/src/dom/queries/interface.dart @@ -23,7 +23,7 @@ import 'package:react_testing_library/src/dom/matches/types.dart'; mixin IQueries { /// @nodoc @protected - Node? Function() get getContainerForScope; + Node Function() get getContainerForScope; /// @nodoc @protected diff --git a/lib/src/dom/scoped_queries.dart b/lib/src/dom/scoped_queries.dart index fb477a06..19479486 100644 --- a/lib/src/dom/scoped_queries.dart +++ b/lib/src/dom/scoped_queries.dart @@ -45,5 +45,5 @@ abstract class ScopedQueries /// @nodoc @protected @override - final Node? Function() getContainerForScope; + final Node Function() getContainerForScope; } diff --git a/lib/src/dom/within.dart b/lib/src/dom/within.dart index 0a71df45..c793922c 100644 --- a/lib/src/dom/within.dart +++ b/lib/src/dom/within.dart @@ -32,7 +32,7 @@ class WithinQueries extends ScopedQueries { WithinQueries._(this.container) : super(() => container); /// The node within which the queries are scoped. - final Node? container; + final Node container; } /// Takes a DOM [node] and binds it to the raw query functions. @@ -66,7 +66,7 @@ WithinQueries within(Node? node) { @sealed class ScreenQueries extends WithinQueries { - ScreenQueries._() : super._(document.body); + ScreenQueries._() : super._(document.body!); /// A shortcut to print `prettyDOM(document.body)`. /// diff --git a/test/unit/dom/accessibility_helpers_test.dart b/test/unit/dom/accessibility_helpers_test.dart index 506d0e4f..f5733c2b 100644 --- a/test/unit/dom/accessibility_helpers_test.dart +++ b/test/unit/dom/accessibility_helpers_test.dart @@ -185,7 +185,7 @@ void main() { }); group('getRoles', () { - Map _getLoggedRoleMatches(Node? dom, {bool hidden = false}) { + Map _getLoggedRoleMatches(Node dom, {bool hidden = false}) { final rolePattern = RegExp(r'(\w*):\n\n((.|(\n(?!-)))*)\n\n---'); final printCalls = recordPrintCalls(() => rtl.logRoles(dom, hidden: hidden)); expect(printCalls, hasLength(1)); diff --git a/test/unit/dom/matchers/is_in_the_document_test.dart b/test/unit/dom/matchers/is_in_the_document_test.dart index a422e59d..c40057bc 100644 --- a/test/unit/dom/matchers/is_in_the_document_test.dart +++ b/test/unit/dom/matchers/is_in_the_document_test.dart @@ -36,7 +36,7 @@ void main() { // ignore: unnecessary_cast final view = render(ShadowNested({}, react.span({defaultTestIdKey: 'empty'})) as ReactElement); final nodeWithShadowRoot = view.getByTestId(nodeWithShadowRootDefaultTestId); - shouldPass(within(nodeWithShadowRoot.shadowRoot).getByTestId('empty'), isInTheDocument); + shouldPass(within(nodeWithShadowRoot.shadowRoot!).getByTestId('empty'), isInTheDocument); }); group('provides a useful failure message when', () { diff --git a/test/unit/dom/within_test.dart b/test/unit/dom/within_test.dart index a0cc58c7..04f2a59d 100644 --- a/test/unit/dom/within_test.dart +++ b/test/unit/dom/within_test.dart @@ -45,7 +45,7 @@ void main() { final elsForQuerying = elementsForQuerying(''); final view = rtl.render(elsForQuerying); final nodeWithShadowRoot = view.getByTestId(nodeWithShadowRootDefaultTestId); - expect(rtl.within(nodeWithShadowRoot.shadowRoot).getByRole('button'), isA()); + expect(rtl.within(nodeWithShadowRoot.shadowRoot!).getByRole('button'), isA()); }); }); diff --git a/test/unit/user_event/hover_test.dart b/test/unit/user_event/hover_test.dart index 1eaca62f..e04e5a7a 100644 --- a/test/unit/user_event/hover_test.dart +++ b/test/unit/user_event/hover_test.dart @@ -19,6 +19,7 @@ import 'package:react/react.dart' as react; import 'package:react/react_client.dart' show ReactDartFunctionComponentFactoryProxy; import 'package:react_testing_library/matchers.dart'; import 'package:react_testing_library/react_testing_library.dart' as rtl; +import 'package:react_testing_library/src/dom/queries/by_role.dart'; import 'package:react_testing_library/user_event.dart'; import 'package:test/test.dart'; @@ -55,6 +56,8 @@ void main() { UserEvent.unhover(view.getByRole('button')); expect(view.queryByText('Hello!'), isNull); _verifyHoverEvent(); + + jsGetByRole(null, 'abc'); }); test('eventInit', () { From afbcab2cebf549b4771cf6ee403c950987fc9e37 Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Wed, 15 Nov 2023 16:20:31 -0700 Subject: [PATCH 23/31] Refactor waitFor onDone function --- lib/src/dom/async/types.dart | 2 +- lib/src/dom/async/wait_for.dart | 58 ++++++++++--------- .../matchers/jest_dom/is_in_the_document.dart | 1 + lib/src/util/is_or_contains.dart | 1 + test/unit/dom/wait_for_test.dart | 13 +---- test/unit/user_event/hover_test.dart | 3 - 6 files changed, 37 insertions(+), 41 deletions(-) diff --git a/lib/src/dom/async/types.dart b/lib/src/dom/async/types.dart index 4af725b4..a9252a24 100644 --- a/lib/src/dom/async/types.dart +++ b/lib/src/dom/async/types.dart @@ -21,7 +21,7 @@ import 'package:meta/meta.dart'; /// A function typedef used by `onTimeout` parameters in asynchronous `find*` / `waitFor` queries. /// /// Returns either an `Error` or a `TestFailure` when provided with the [originalError]. -typedef QueryTimeoutFn = /*Error || TestFailure*/ Object? Function(/*Error*/ Object? originalError); +typedef QueryTimeoutFn = /*Error || TestFailure*/ Object Function(/*Error*/ Object originalError); @JS() @anonymous diff --git a/lib/src/dom/async/wait_for.dart b/lib/src/dom/async/wait_for.dart index 78a1ec5c..8e95ede3 100644 --- a/lib/src/dom/async/wait_for.dart +++ b/lib/src/dom/async/wait_for.dart @@ -53,7 +53,7 @@ export 'package:react_testing_library/src/dom/async/types.dart' show JsMutationO /// /// {@category Async} Future waitFor( - FutureOr? Function() expectation, { + FutureOr Function() expectation, { Node? container, Duration? timeout, Duration interval = const Duration(milliseconds: 50), @@ -61,41 +61,45 @@ Future waitFor( MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) async { final config = getConfig(); - container ??= document.body; + container ??= document.body!; timeout ??= Duration(milliseconds: config.asyncUtilTimeout); onTimeout ??= (error) => error; - /*Error*/ dynamic lastError; + /*Error*/ Object? lastError; late MutationObserver observer; late Timer intervalTimer; late Timer overallTimeoutTimer; var isPending = false; final doneCompleter = Completer(); - void onDone(Object? error, T? result) { + void onDone(T result) { if (doneCompleter.isCompleted) return; overallTimeoutTimer.cancel(); intervalTimer.cancel(); observer.disconnect(); - if (error != null) { - doneCompleter.completeError(error); - } else if (result is TestFailure) { + if (result is TestFailure) { doneCompleter.completeError(result); } else { doneCompleter.complete(result); } } + // Separate error handling to enforce non-nullability of the result. + void onDoneWithError(Object error) { + if (doneCompleter.isCompleted) return; + + overallTimeoutTimer.cancel(); + intervalTimer.cancel(); + observer.disconnect(); + + doneCompleter.completeError(error); + } + void handleTimeout() { - /*Error*/ dynamic error; - if (lastError != null) { - error = lastError; - } else { - error = TimeoutException('Timed out in waitFor after ${timeout!.inMilliseconds}ms.'); - } - onDone(onTimeout!(error), null); + final error = lastError ?? TimeoutException('Timed out in waitFor after ${timeout!.inMilliseconds}ms.'); + onDoneWithError(onTimeout!(error)); } void checkCallback() { @@ -105,10 +109,10 @@ Future waitFor( if (result is Future) { isPending = true; (result! as Future) - .then((resolvedValue) => onDone(null, resolvedValue as T), onError: (e) => lastError = e) + .then((resolvedValue) => onDone(resolvedValue as T), onError: (e) => lastError = e) .whenComplete(() => isPending = false); } else { - onDone(null, result); + onDone(result); } // If `callback` throws, wait for the next mutation, interval, or timeout. } catch (error) { @@ -121,7 +125,7 @@ Future waitFor( intervalTimer = Timer.periodic(interval, (_) => checkCallback()); observer = MutationObserver((_, __) => checkCallback()) ..observe( - container!, + container, childList: mutationObserverOptions.childList, attributes: mutationObserverOptions.attributes, characterData: mutationObserverOptions.characterData, @@ -164,16 +168,14 @@ Future waitForElementToBeRemoved( MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) async { final config = getConfig(); - container ??= document.body; + container ??= document.body!; timeout ??= Duration(milliseconds: config.asyncUtilTimeout); final el = callback(); - // ignore: unnecessary_null_comparison - if (el == null) { - throw TestingLibraryElementError('The callback must return a non-null Element.'); - } + // Keep null check to maintain backwards compatibility for consumers that are not opted in to null safety. + ArgumentError.checkNotNull(el); - if (!container!.contains(el)) { + if (!container.contains(el)) { throw TestingLibraryElementError( 'The element returned from the callback was not present in the container at the time waitForElementToBeRemoved() was called:\n\n' '${prettyDOM(container)}'); @@ -221,16 +223,18 @@ Future waitForElementsToBeRemoved( QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) async { - container ??= document.body; + container ??= document.body!; final els = callback(); - // ignore: unnecessary_null_comparison - if (els == null || els.isEmpty) { + // Keep null check to maintain backwards compatibility for consumers that are not opted in to null safety. + ArgumentError.checkNotNull(els); + + if (els.isEmpty) { throw TestingLibraryElementError('The callback must return one or more non-null Elements.'); } for (final el in els) { - if (!container!.contains(el)) { + if (!container.contains(el)) { throw TestingLibraryElementError( 'One of the elements returned from the callback was not present in the container at the time waitForElementsToBeRemoved() was called:\n\n' '${prettyDOM(container)}'); diff --git a/lib/src/matchers/jest_dom/is_in_the_document.dart b/lib/src/matchers/jest_dom/is_in_the_document.dart index f668dfa5..eaa018eb 100644 --- a/lib/src/matchers/jest_dom/is_in_the_document.dart +++ b/lib/src/matchers/jest_dom/is_in_the_document.dart @@ -76,6 +76,7 @@ class _IsInTheDocument extends Matcher { @override bool matches(dynamic item, Map matchState) { if (item is! Element) return false; + // Keep null check to maintain backwards compatibility for consumers that are not opted in to null safety. // ignore: unnecessary_null_comparison return item != null && item.ownerDocument == item.getRootNode({'composed': true}); } diff --git a/lib/src/util/is_or_contains.dart b/lib/src/util/is_or_contains.dart index 78a0eda3..4d730753 100644 --- a/lib/src/util/is_or_contains.dart +++ b/lib/src/util/is_or_contains.dart @@ -17,5 +17,6 @@ import 'dart:html' show Node; /// Returns whether [root] is the same as or contains the [other] node. /// /// Returns false if either [root] or [other] is null. +// Keep null check to maintain backwards compatibility for consumers that are not opted in to null safety. // ignore: unnecessary_null_comparison bool isOrContains(Node root, Node other) => (root != null && other != null) && (root == other || root.contains(other)); diff --git a/test/unit/dom/wait_for_test.dart b/test/unit/dom/wait_for_test.dart index af621b8e..62debaa1 100644 --- a/test/unit/dom/wait_for_test.dart +++ b/test/unit/dom/wait_for_test.dart @@ -36,10 +36,7 @@ void main() { group('waitFor()', () { setUp(() { - view = - // TODO: Remove ignore once we stop supporting Dart SDK 2.7.x - // ignore: unnecessary_cast - rtl.render(DelayedRenderOf({'childrenToRenderAfterDelay': elementsForQuerying('waitFor')}) as ReactElement); + view = rtl.render(DelayedRenderOf({'childrenToRenderAfterDelay': elementsForQuerying('waitFor')})); rootElement = view.getByTestId('delayed-render-of-root'); }); @@ -201,8 +198,6 @@ void main() { setUp(() { expect(shortTimeout, lessThan(delayAfterWhichTheElementWillBeRemoved), reason: 'test setup sanity check'); - // TODO: Remove ignore once we stop supporting Dart SDK 2.7.x - // ignore: unnecessary_cast view = rtl.render(react.div( {}, 'wontBeRemoved', @@ -214,7 +209,7 @@ void main() { {}, react.div({}, 'willBeRemoved'), elementsForQuerying('waitForElementToBeRemoved'), - ))) as ReactElement); + )))); elementThatWillBeRemovedAfterDelay = view.getByText('willBeRemoved'); elementThatWontBeRemoved = view.getByText('wontBeRemoved'); elementInDomButOutsideContainer = document.body!.append(DivElement() @@ -285,8 +280,6 @@ void main() { setUp(() { expect(shortTimeout, lessThan(delayAfterWhichTheElementWillBeRemoved), reason: 'test setup sanity check'); - // TODO: Remove ignore once we stop supporting Dart SDK 2.7.x - // ignore: unnecessary_cast view = rtl.render(DelayedRenderOf( { 'childrenToRenderAfterDelay': elementsForQuerying('waitForElementToBeRemoved'), @@ -298,7 +291,7 @@ void main() { react.div({}, 'willNotBeRemoved'), elementsForQuerying('waitForElementToBeRemoved'), ), - ) as ReactElement); + )); elementThatWillBeRemovedAfterDelay = view.getByText('willBeRemoved'); anotherElementThatWillBeRemovedAfterDelay = view.getByText('willAlsoBeRemoved'); elementThatWillNotBeRemovedAfterDelay = view.getByText('willNotBeRemoved'); diff --git a/test/unit/user_event/hover_test.dart b/test/unit/user_event/hover_test.dart index e04e5a7a..1eaca62f 100644 --- a/test/unit/user_event/hover_test.dart +++ b/test/unit/user_event/hover_test.dart @@ -19,7 +19,6 @@ import 'package:react/react.dart' as react; import 'package:react/react_client.dart' show ReactDartFunctionComponentFactoryProxy; import 'package:react_testing_library/matchers.dart'; import 'package:react_testing_library/react_testing_library.dart' as rtl; -import 'package:react_testing_library/src/dom/queries/by_role.dart'; import 'package:react_testing_library/user_event.dart'; import 'package:test/test.dart'; @@ -56,8 +55,6 @@ void main() { UserEvent.unhover(view.getByRole('button')); expect(view.queryByText('Hello!'), isNull); _verifyHoverEvent(); - - jsGetByRole(null, 'abc'); }); test('eventInit', () { From a02b547e68bc043960c8f254611c56defde24539 Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Wed, 15 Nov 2023 16:24:05 -0700 Subject: [PATCH 24/31] Reformat accessibility helpers --- lib/src/dom/accessibility_helpers.dart | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/src/dom/accessibility_helpers.dart b/lib/src/dom/accessibility_helpers.dart index c95ba6f7..fe8bf5ce 100644 --- a/lib/src/dom/accessibility_helpers.dart +++ b/lib/src/dom/accessibility_helpers.dart @@ -32,9 +32,8 @@ import 'package:react_testing_library/src/util/console_log_utils.dart'; /// > Learn more: /// /// {@category Accessibility} -Map getRoles(Node container, {bool hidden = false}) { - return Map.from(JsBackedMap.fromJs(_getRoles(container, jsifyAndAllowInterop({'hidden': hidden}) as JsMap))); -} +Map getRoles(Node container, {bool hidden = false}) => + Map.from(JsBackedMap.fromJs(_getRoles(container, jsifyAndAllowInterop({'hidden': hidden}) as JsMap))); /// Prints a list of all the implicit ARIA roles within [container], each role containing a list of all of the /// nodes which match that role. @@ -46,9 +45,8 @@ Map getRoles(Node container, {bool hidden = false}) { /// > Learn more: /// /// {@category Accessibility} -void logRoles(Node container, {bool hidden = false}) { - printConsoleLogs(() => _logRoles(container, jsifyAndAllowInterop({'hidden': hidden}) as JsMap)); -} +void logRoles(Node container, {bool hidden = false}) => + printConsoleLogs(() => _logRoles(container, jsifyAndAllowInterop({'hidden': hidden}) as JsMap)); @JS('rtl.getRoles') external JsMap _getRoles( From 951a13591e844586ac7639176a8503885adc0c1b Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Wed, 15 Nov 2023 17:00:11 -0700 Subject: [PATCH 25/31] Update fireEventByName --- lib/src/dom/async/types.dart | 1 + lib/src/dom/config/types.dart | 4 ++-- lib/src/dom/fire_event.dart | 11 ++++------- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/src/dom/async/types.dart b/lib/src/dom/async/types.dart index a9252a24..1540cf2b 100644 --- a/lib/src/dom/async/types.dart +++ b/lib/src/dom/async/types.dart @@ -23,6 +23,7 @@ import 'package:meta/meta.dart'; /// Returns either an `Error` or a `TestFailure` when provided with the [originalError]. typedef QueryTimeoutFn = /*Error || TestFailure*/ Object Function(/*Error*/ Object originalError); +// todo should all these be optional / nullable? @JS() @anonymous class SharedJsWaitForOptions { diff --git a/lib/src/dom/config/types.dart b/lib/src/dom/config/types.dart index 6c93b187..2a8f20a8 100644 --- a/lib/src/dom/config/types.dart +++ b/lib/src/dom/config/types.dart @@ -40,6 +40,6 @@ class JsConfig { external bool get throwSuggestions; external set throwSuggestions(bool value); - external /*JsError*/ dynamic Function(String message, Element container) get getElementError; - external set getElementError(/*JsError*/ dynamic Function(String message, Element container) value); + external /*JsError*/ dynamic Function(String? message, Element container) get getElementError; + external set getElementError(/*JsError*/ dynamic Function(String? message, Element container) value); } diff --git a/lib/src/dom/fire_event.dart b/lib/src/dom/fire_event.dart index 5045773c..98db1d4c 100644 --- a/lib/src/dom/fire_event.dart +++ b/lib/src/dom/fire_event.dart @@ -124,19 +124,16 @@ external JsMap get _fireEventObj; /// /// {@category UserActions} bool fireEventByName(String eventName, Element element, [Map? eventProperties]) { - if (!JsBackedMap.fromJs(_jsEventMap).keys.contains(eventName)) { + if (!JsBackedMap.fromJs(_fireEventObj).keys.contains(eventName)) { throw ArgumentError.value(eventName, 'eventName'); } final jsFireEventByNameFn = - JsBackedMap.fromJs(_fireEventObj)[eventName] as bool Function(Element, [/*JsObject*/ dynamic])?; + JsBackedMap.fromJs(_fireEventObj)[eventName] as bool Function(Element, [/*JsObject*/ dynamic]); if (eventProperties == null) { - return eventHandlerErrorCatcher(() => jsFireEventByNameFn!(element)); + return eventHandlerErrorCatcher(() => jsFireEventByNameFn(element)); } - return eventHandlerErrorCatcher(() => jsFireEventByNameFn!(element, jsifyAndAllowInterop(eventProperties))); + return eventHandlerErrorCatcher(() => jsFireEventByNameFn(element, jsifyAndAllowInterop(eventProperties))); } - -@JS('rtl.eventMap') -external JsMap get _jsEventMap; From 9566232ba7f1917110bf1636e76ad7b9ba544a30 Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Mon, 20 Nov 2023 12:20:10 -0700 Subject: [PATCH 26/31] Add prettyDom test --- lib/src/dom/matches/types.dart | 6 +++--- lib/src/dom/pretty_dom.dart | 12 ++++++------ test/unit/dom/pretty_dom_test.dart | 21 +++++++++++++++++++++ test/unit/dom/wait_for_test.dart | 1 - 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/lib/src/dom/matches/types.dart b/lib/src/dom/matches/types.dart index ebde427f..43154aec 100644 --- a/lib/src/dom/matches/types.dart +++ b/lib/src/dom/matches/types.dart @@ -82,7 +82,7 @@ abstract class TextMatch { return (originalMessage, container) { final newMessage = originalMessage.toString().replaceAllMapped(dartInteropFunctionValueRegex, (match) { final optionalOpeningQuoteOrBacktick = match.group(1)!; - final optionalClosingQuoteOrBacktick = match.group(3); + final optionalClosingQuoteOrBacktick = match.group(3)!; final newValueLines = newValue.toString().split('\n'); var restOfMessageBeforePrettyDomOrAccessibleRolesPrintout = match.group(4); if (newValueLines.length > 1) { @@ -91,7 +91,7 @@ abstract class TextMatch { restOfMessageBeforePrettyDomOrAccessibleRolesPrintout!.replaceFirst(RegExp(r'^\s*\.*\s*'), ''); } var returnValue = '${newValueLines.join('\n')}$restOfMessageBeforePrettyDomOrAccessibleRolesPrintout'; - if (optionalOpeningQuoteOrBacktick.isNotEmpty || optionalClosingQuoteOrBacktick!.isNotEmpty) { + if (optionalOpeningQuoteOrBacktick.isNotEmpty || optionalClosingQuoteOrBacktick.isNotEmpty) { // Restore quotes around the function/regexp portion of the new value if they were previously found around // the `function...` dart interop portion of the original message. returnValue = returnValue.replaceAllMapped( @@ -187,4 +187,4 @@ class NormalizerOptions { } /// The function signature for a custom `normalizer` argument in a query. -typedef NormalizerFn = String Function(String?); +typedef NormalizerFn = String Function(String); diff --git a/lib/src/dom/pretty_dom.dart b/lib/src/dom/pretty_dom.dart index 16264c78..77a1971a 100644 --- a/lib/src/dom/pretty_dom.dart +++ b/lib/src/dom/pretty_dom.dart @@ -82,20 +82,20 @@ class PrettyDomOptions { /// ### [indent] /// The number of spaces in each level of indentation, defaulting to `2`. /// {@endtemplate} - external int get indent; - external set indent(int value); + external int? get indent; + external set indent(int? value); /// {@template prettyDomOptionsMaxDepth} /// ### [maxDepth] /// The number of nested levels to print in the DOM tree. /// {@endtemplate} - external int get maxDepth; - external set maxDepth(int value); + external int? get maxDepth; + external set maxDepth(int? value); /// {@template prettyDomOptionsMin} /// ### [min] /// Whether to minimize added space: no indentation nor line breaks. Defaults to `false`. /// {@endtemplate} - external bool get min; - external set min(bool value); + external bool? get min; + external set min(bool? value); } diff --git a/test/unit/dom/pretty_dom_test.dart b/test/unit/dom/pretty_dom_test.dart index e84fa89a..9da9bbcc 100644 --- a/test/unit/dom/pretty_dom_test.dart +++ b/test/unit/dom/pretty_dom_test.dart @@ -55,6 +55,10 @@ void main() { test('when min is true', () { expect(rtl.prettyDOM(vDomRootRef.current, min: true), _expectedPrettyDomWithMinSetToTrue); }); + + test('with null input', () { + expect(rtl.prettyDOM(null), _expectedPrettyDomNull); + }); }); }); } @@ -95,3 +99,20 @@ const _expectedPrettyDomWithMaxDepthOfTwo = '''
'''; const _expectedPrettyDomWithMinSetToTrue = '

hi there!

you again?

'; + +const _expectedPrettyDomNull = ''' + + +
+
+

+ hi there! +

+
+

+ you again? +

+
+
+
+'''; diff --git a/test/unit/dom/wait_for_test.dart b/test/unit/dom/wait_for_test.dart index 62debaa1..b0b6ae1b 100644 --- a/test/unit/dom/wait_for_test.dart +++ b/test/unit/dom/wait_for_test.dart @@ -16,7 +16,6 @@ import 'dart:async'; import 'dart:html'; import 'package:react/react.dart' as react; -import 'package:react/react_client.dart' show ReactElement; import 'package:react_testing_library/react_testing_library.dart' as rtl; import 'package:react_testing_library/src/util/error_message_utils.dart'; import 'package:test/test.dart'; From fecb0b14a2edb8a4510f441ffdcdc750a76e0ed5 Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Mon, 20 Nov 2023 17:10:40 -0700 Subject: [PATCH 27/31] Update dom queries --- lib/src/dom/async/types.dart | 30 +++++------ lib/src/dom/async/wait_for.dart | 2 +- lib/src/dom/matches/types.dart | 20 ++++---- lib/src/dom/queries/by_alt_text.dart | 16 +++--- lib/src/dom/queries/by_display_value.dart | 29 ++++++----- lib/src/dom/queries/by_label_text.dart | 16 +++--- lib/src/dom/queries/by_placeholder_text.dart | 16 +++--- lib/src/dom/queries/by_role.dart | 52 ++++++++++---------- lib/src/dom/queries/by_testid.dart | 16 +++--- lib/src/dom/queries/by_text.dart | 16 +++--- lib/src/dom/queries/by_title.dart | 16 +++--- lib/src/dom/queries/interface.dart | 1 + lib/src/dom/top_level_queries.dart | 34 ++++++------- 13 files changed, 132 insertions(+), 132 deletions(-) diff --git a/lib/src/dom/async/types.dart b/lib/src/dom/async/types.dart index 1540cf2b..b2d12793 100644 --- a/lib/src/dom/async/types.dart +++ b/lib/src/dom/async/types.dart @@ -17,13 +17,13 @@ library react_testing_library.src.dom.async.types; import 'package:js/js.dart'; import 'package:meta/meta.dart'; +import 'package:react_testing_library/src/dom/config/configure.dart' show getConfig; /// A function typedef used by `onTimeout` parameters in asynchronous `find*` / `waitFor` queries. /// /// Returns either an `Error` or a `TestFailure` when provided with the [originalError]. typedef QueryTimeoutFn = /*Error || TestFailure*/ Object Function(/*Error*/ Object originalError); -// todo should all these be optional / nullable? @JS() @anonymous class SharedJsWaitForOptions { @@ -32,16 +32,16 @@ class SharedJsWaitForOptions { /// /// How long to wait for the node to appear in the DOM before throwing a `TestFailure`, defaulting to `1000ms`. /// {@endtemplate} - external int get timeout; - external set timeout(int value); + external int? get timeout; + external set timeout(int? value); /// {@template sharedWaitForOptionsIntervalDescription} /// ### [interval] /// /// How often the callback is called, defaulting to `50ms`. /// {@endtemplate} - external int get interval; - external set interval(int value); + external int? get interval; + external set interval(int? value); /// {@template sharedWaitForOptionsOnTimeoutDescription} /// ### [onTimeout] @@ -72,20 +72,20 @@ class SharedJsWaitForOptions { @JS() @anonymous class JsMutationObserverOptions { - external bool get subtree; - external set subtree(bool value); + external bool? get subtree; + external set subtree(bool? value); - external bool get childList; - external set childList(bool value); + external bool? get childList; + external set childList(bool? value); - external bool get attributes; - external set attributes(bool value); + external bool? get attributes; + external set attributes(bool? value); - external bool get characterData; - external set characterData(bool value); + external bool? get characterData; + external set characterData(bool? value); - external List get attributeFilter; - external set attributeFilter(List value); + external List? get attributeFilter; + external set attributeFilter(List? value); } /// Builds a set of options that can be used for any async query like `waitFor`, diff --git a/lib/src/dom/async/wait_for.dart b/lib/src/dom/async/wait_for.dart index 8e95ede3..d57219e7 100644 --- a/lib/src/dom/async/wait_for.dart +++ b/lib/src/dom/async/wait_for.dart @@ -56,7 +56,7 @@ Future waitFor( FutureOr Function() expectation, { Node? container, Duration? timeout, - Duration interval = const Duration(milliseconds: 50), + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) async { diff --git a/lib/src/dom/matches/types.dart b/lib/src/dom/matches/types.dart index 43154aec..447213e7 100644 --- a/lib/src/dom/matches/types.dart +++ b/lib/src/dom/matches/types.dart @@ -118,8 +118,8 @@ class MatcherOptions { /// not case-sensitive. It has no effect on regex or function arguments. In most cases using a regex /// instead of a string gives you more control over fuzzy matching and should be preferred over `exact: false`. /// {@endtemplate} - external bool get exact; - external set exact(bool value); + external bool? get exact; + external set exact(bool? value); /// {@template MatcherOptionsNormalizerArgDescription} /// ### [normalizer] @@ -142,8 +142,8 @@ class MatcherOptions { /// [JS `TextMatch` normalization](https://testing-library.com/docs/queries/about#normalization) docs /// for more details and examples. /// {@endtemplate} - external NormalizerFn Function([NormalizerOptions]) get normalizer; - external set normalizer(NormalizerFn Function([NormalizerOptions]) value); + external NormalizerFn Function([NormalizerOptions?])? get normalizer; + external set normalizer(NormalizerFn Function([NormalizerOptions?])? value); /// {@template MatcherOptionsSelectorArgDescription} /// ### [selector] @@ -151,8 +151,8 @@ class MatcherOptions { /// Set `selector` to a CSS selector that will narrow the scope of the existing query to /// only match element(s) that match the selector. /// {@endtemplate} - external String get selector; - external set selector(String value); + external String? get selector; + external set selector(String? value); /// {@template MatcherOptionsIgnoreArgDescription} /// ### [ignore] @@ -174,16 +174,16 @@ class MatcherOptions { @anonymous class NormalizerOptions { /// Whether leading / trailing whitespace will be trimmed. - external bool get trim; + external bool? get trim; /// Whether leading / trailing whitespace should be trimmed. - external set trim(bool value); + external set trim(bool? value); /// Whether multiple spaces will be collapsed into a single space. - external bool get collapseWhitespace; + external bool? get collapseWhitespace; /// Whether multiple spaces should be collapsed into a single space. - external set collapseWhitespace(bool value); + external set collapseWhitespace(bool? value); } /// The function signature for a custom `normalizer` argument in a query. diff --git a/lib/src/dom/queries/by_alt_text.dart b/lib/src/dom/queries/by_alt_text.dart index 90974731..4a231bae 100644 --- a/lib/src/dom/queries/by_alt_text.dart +++ b/lib/src/dom/queries/by_alt_text.dart @@ -236,9 +236,9 @@ mixin ByAltTextQueries on IQueries { bool exact = true, NormalizerFn Function([NormalizerOptions?])? normalizer, Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, - MutationObserverOptions? mutationObserverOptions, + MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getByAltText` instead of an // interop like `_jsFindByAltText` to give consumers better async stack traces. @@ -250,9 +250,9 @@ mixin ByAltTextQueries on IQueries { ), container: getContainerForScope(), timeout: timeout, - interval: interval ?? defaultAsyncCallbackCheckInterval, + interval: interval, onTimeout: onTimeout, - mutationObserverOptions: mutationObserverOptions ?? defaultMutationObserverOptions, + mutationObserverOptions: mutationObserverOptions, ); } @@ -292,9 +292,9 @@ mixin ByAltTextQueries on IQueries { bool exact = true, NormalizerFn Function([NormalizerOptions?])? normalizer, Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, - MutationObserverOptions? mutationObserverOptions, + MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getAllByAltText` instead of an // interop like `_jsFindAllByAltText` to give consumers better async stack traces. @@ -306,9 +306,9 @@ mixin ByAltTextQueries on IQueries { ), container: getContainerForScope(), timeout: timeout, - interval: interval ?? defaultAsyncCallbackCheckInterval, + interval: interval, onTimeout: onTimeout, - mutationObserverOptions: mutationObserverOptions ?? defaultMutationObserverOptions, + mutationObserverOptions: mutationObserverOptions, ); } } diff --git a/lib/src/dom/queries/by_display_value.dart b/lib/src/dom/queries/by_display_value.dart index cfad4b12..bf81c917 100644 --- a/lib/src/dom/queries/by_display_value.dart +++ b/lib/src/dom/queries/by_display_value.dart @@ -187,13 +187,12 @@ mixin ByDisplayValueQueries on IQueries { /*TextMatch*/ dynamic value, { bool exact = true, NormalizerFn Function([NormalizerOptions?])? normalizer, - }) { - return _jsQueryByDisplayValue( - getContainerForScope(), - TextMatch.toJs(value), - buildMatcherOptions(exact: exact, normalizer: normalizer), - ) as E?; - } + }) => + _jsQueryByDisplayValue( + getContainerForScope(), + TextMatch.toJs(value), + buildMatcherOptions(exact: exact, normalizer: normalizer), + ) as E?; /// Returns a list of [InputElement]s, [TextAreaElement]s or [SelectElement]s that have the matching [value] displayed, /// defaulting to an [exact] match. @@ -262,9 +261,9 @@ mixin ByDisplayValueQueries on IQueries { bool exact = true, NormalizerFn Function([NormalizerOptions?])? normalizer, Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, - MutationObserverOptions? mutationObserverOptions, + MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getByDisplayValue` instead of an // interop like `_jsFindByDisplayValue` to give consumers better async stack traces. @@ -276,9 +275,9 @@ mixin ByDisplayValueQueries on IQueries { ), container: getContainerForScope(), timeout: timeout, - interval: interval ?? defaultAsyncCallbackCheckInterval, + interval: interval, onTimeout: onTimeout, - mutationObserverOptions: mutationObserverOptions ?? defaultMutationObserverOptions, + mutationObserverOptions: mutationObserverOptions, ); } @@ -317,9 +316,9 @@ mixin ByDisplayValueQueries on IQueries { bool exact = true, NormalizerFn Function([NormalizerOptions?])? normalizer, Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, - MutationObserverOptions? mutationObserverOptions, + MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getAllByDisplayValue` instead of an // interop like `_jsFindAllByDisplayValue` to give consumers better async stack traces. @@ -331,9 +330,9 @@ mixin ByDisplayValueQueries on IQueries { ), container: getContainerForScope(), timeout: timeout, - interval: interval ?? defaultAsyncCallbackCheckInterval, + interval: interval, onTimeout: onTimeout, - mutationObserverOptions: mutationObserverOptions ?? defaultMutationObserverOptions, + mutationObserverOptions: mutationObserverOptions, ); } } diff --git a/lib/src/dom/queries/by_label_text.dart b/lib/src/dom/queries/by_label_text.dart index 8995c2ac..7ca5a714 100644 --- a/lib/src/dom/queries/by_label_text.dart +++ b/lib/src/dom/queries/by_label_text.dart @@ -254,9 +254,9 @@ mixin ByLabelTextQueries on IQueries { NormalizerFn Function([NormalizerOptions?])? normalizer, String? selector, Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, - MutationObserverOptions? mutationObserverOptions, + MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getByLabelText` instead of an // interop like `_jsFindByLabelText` to give consumers better async stack traces. @@ -269,9 +269,9 @@ mixin ByLabelTextQueries on IQueries { ), container: getContainerForScope(), timeout: timeout, - interval: interval ?? defaultAsyncCallbackCheckInterval, + interval: interval, onTimeout: onTimeout, - mutationObserverOptions: mutationObserverOptions ?? defaultMutationObserverOptions, + mutationObserverOptions: mutationObserverOptions, ); } @@ -310,9 +310,9 @@ mixin ByLabelTextQueries on IQueries { NormalizerFn Function([NormalizerOptions?])? normalizer, String? selector, Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, - MutationObserverOptions? mutationObserverOptions, + MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getAllByAltText` instead of an // interop like `_jsFindAllByAltText` to give consumers better async stack traces. @@ -325,9 +325,9 @@ mixin ByLabelTextQueries on IQueries { ), container: getContainerForScope(), timeout: timeout, - interval: interval ?? defaultAsyncCallbackCheckInterval, + interval: interval, onTimeout: onTimeout, - mutationObserverOptions: mutationObserverOptions ?? defaultMutationObserverOptions, + mutationObserverOptions: mutationObserverOptions, ); } } diff --git a/lib/src/dom/queries/by_placeholder_text.dart b/lib/src/dom/queries/by_placeholder_text.dart index d2738f50..beb8b67b 100644 --- a/lib/src/dom/queries/by_placeholder_text.dart +++ b/lib/src/dom/queries/by_placeholder_text.dart @@ -231,9 +231,9 @@ mixin ByPlaceholderTextQueries on IQueries { bool exact = true, NormalizerFn Function([NormalizerOptions?])? normalizer, Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, - MutationObserverOptions? mutationObserverOptions, + MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getByPlaceholderText` instead of an // interop like `_jsFindByPlaceholderText` to give consumers better async stack traces. @@ -245,9 +245,9 @@ mixin ByPlaceholderTextQueries on IQueries { ), container: getContainerForScope(), timeout: timeout, - interval: interval ?? defaultAsyncCallbackCheckInterval, + interval: interval, onTimeout: onTimeout, - mutationObserverOptions: mutationObserverOptions ?? defaultMutationObserverOptions, + mutationObserverOptions: mutationObserverOptions, ); } @@ -286,9 +286,9 @@ mixin ByPlaceholderTextQueries on IQueries { bool exact = true, NormalizerFn Function([NormalizerOptions?])? normalizer, Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, - MutationObserverOptions? mutationObserverOptions, + MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getAllByPlaceholderText` instead of an // interop like `_jsFindAllByPlaceholderText` to give consumers better async stack traces. @@ -300,9 +300,9 @@ mixin ByPlaceholderTextQueries on IQueries { ), container: getContainerForScope(), timeout: timeout, - interval: interval ?? defaultAsyncCallbackCheckInterval, + interval: interval, onTimeout: onTimeout, - mutationObserverOptions: mutationObserverOptions ?? defaultMutationObserverOptions, + mutationObserverOptions: mutationObserverOptions, ); } } diff --git a/lib/src/dom/queries/by_role.dart b/lib/src/dom/queries/by_role.dart index 08cfe6f3..5fdf834e 100644 --- a/lib/src/dom/queries/by_role.dart +++ b/lib/src/dom/queries/by_role.dart @@ -374,9 +374,9 @@ mixin ByRoleQueries on IQueries { bool queryFallbacks = false, int? level, Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, - MutationObserverOptions? mutationObserverOptions, + MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getByRole` instead of an // interop like `_jsFindByRole` to give consumers better async stack traces. @@ -396,9 +396,9 @@ mixin ByRoleQueries on IQueries { ), container: getContainerForScope(), timeout: timeout, - interval: interval ?? defaultAsyncCallbackCheckInterval, + interval: interval, onTimeout: onTimeout, - mutationObserverOptions: mutationObserverOptions ?? defaultMutationObserverOptions, + mutationObserverOptions: mutationObserverOptions, ); } @@ -452,9 +452,9 @@ mixin ByRoleQueries on IQueries { bool queryFallbacks = false, int? level, Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, - MutationObserverOptions? mutationObserverOptions, + MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getAllByRole` instead of an // interop like `_jsFindAllByRole` to give consumers better async stack traces. @@ -474,9 +474,9 @@ mixin ByRoleQueries on IQueries { ), container: getContainerForScope(), timeout: timeout, - interval: interval ?? defaultAsyncCallbackCheckInterval, + interval: interval, onTimeout: onTimeout, - mutationObserverOptions: mutationObserverOptions ?? defaultMutationObserverOptions, + mutationObserverOptions: mutationObserverOptions, ); } } @@ -512,11 +512,11 @@ external List< /*Element*/ dynamic> _jsQueryAllByRole( @JS() @anonymous class ByRoleOptions { - external bool get exact; - external set exact(bool value); + external bool? get exact; + external set exact(bool? value); - external NormalizerFn Function([NormalizerOptions?]) get normalizer; - external set normalizer(NormalizerFn Function([NormalizerOptions?]) value); + external NormalizerFn Function([NormalizerOptions?])? get normalizer; + external set normalizer(NormalizerFn Function([NormalizerOptions?])? value); /// {@template byRoleOptionsName} /// You can also query the returned element(s) by their [accessible name](https://www.w3.org/TR/accname-1.1/) @@ -543,8 +543,8 @@ class ByRoleOptions { /// /// See: for more details and examples. /// {@endtemplate} - external bool get hidden; - external set hidden(bool value); + external bool? get hidden; + external set hidden(bool? value); /// {@template byRoleOptionsSelected} /// ### [selected] @@ -555,8 +555,8 @@ class ByRoleOptions { /// /// See: for more details and examples. /// {@endtemplate} - external bool get selected; - external set selected(bool value); + external bool? get selected; + external set selected(bool? value); /// {@template byRoleOptionsChecked} /// ### [checked] @@ -564,8 +564,8 @@ class ByRoleOptions { /// /// See: for more details and examples. /// {@endtemplate} - external bool get checked; - external set checked(bool value); + external bool? get checked; + external set checked(bool? value); /// {@template byRoleOptionsPressed} /// ### [pressed] @@ -576,8 +576,8 @@ class ByRoleOptions { /// /// See: for more details and examples. /// {@endtemplate} - external bool get pressed; - external set pressed(bool value); + external bool? get pressed; + external set pressed(bool? value); /// {@template byRoleOptionsExpanded} /// ### [expanded] @@ -588,8 +588,8 @@ class ByRoleOptions { /// /// See: for more details and examples. /// {@endtemplate} - external bool get expanded; - external set expanded(bool value); + external bool? get expanded; + external set expanded(bool? value); /// {@template byRoleOptionsQueryFallbacks} /// ### [queryFallbacks] @@ -599,8 +599,8 @@ class ByRoleOptions { /// /// See: for more details and examples. /// {@endtemplate} - external bool get queryFallbacks; - external set queryFallbacks(bool value); + external bool? get queryFallbacks; + external set queryFallbacks(bool? value); /// {@template byRoleOptionsLevel} /// ### [level] @@ -615,6 +615,6 @@ class ByRoleOptions { /// /// See: for more details and examples. /// {@endtemplate} - external int get level; - external set level(int value); + external int? get level; + external set level(int? value); } diff --git a/lib/src/dom/queries/by_testid.dart b/lib/src/dom/queries/by_testid.dart index f023c695..be6e58c4 100644 --- a/lib/src/dom/queries/by_testid.dart +++ b/lib/src/dom/queries/by_testid.dart @@ -331,9 +331,9 @@ mixin ByTestIdQueries on IQueries { bool exact = true, NormalizerFn Function([NormalizerOptions?])? normalizer, Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, - MutationObserverOptions? mutationObserverOptions, + MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getByTestId` instead of an // interop like `_jsFindByTestId` to give consumers better async stack traces. @@ -345,9 +345,9 @@ mixin ByTestIdQueries on IQueries { ), container: getContainerForScope(), timeout: timeout, - interval: interval ?? defaultAsyncCallbackCheckInterval, + interval: interval, onTimeout: onTimeout, - mutationObserverOptions: mutationObserverOptions ?? defaultMutationObserverOptions, + mutationObserverOptions: mutationObserverOptions, ); } @@ -386,9 +386,9 @@ mixin ByTestIdQueries on IQueries { bool exact = true, NormalizerFn Function([NormalizerOptions?])? normalizer, Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, - MutationObserverOptions? mutationObserverOptions, + MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getAllByTestId` instead of an // interop like `_jsFindAllByTestId` to give consumers better async stack traces. @@ -400,9 +400,9 @@ mixin ByTestIdQueries on IQueries { ), container: getContainerForScope(), timeout: timeout, - interval: interval ?? defaultAsyncCallbackCheckInterval, + interval: interval, onTimeout: onTimeout, - mutationObserverOptions: mutationObserverOptions ?? defaultMutationObserverOptions, + mutationObserverOptions: mutationObserverOptions, ); } } diff --git a/lib/src/dom/queries/by_text.dart b/lib/src/dom/queries/by_text.dart index 78a2f545..472e5979 100644 --- a/lib/src/dom/queries/by_text.dart +++ b/lib/src/dom/queries/by_text.dart @@ -252,9 +252,9 @@ mixin ByTextQueries on IQueries { String? selector, /*String|bool*/ dynamic ignore = 'script', Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, - MutationObserverOptions? mutationObserverOptions, + MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getByText` instead of an // interop like `_jsFindByText` to give consumers better async stack traces. @@ -268,9 +268,9 @@ mixin ByTextQueries on IQueries { ), container: getContainerForScope(), timeout: timeout, - interval: interval ?? defaultAsyncCallbackCheckInterval, + interval: interval, onTimeout: onTimeout, - mutationObserverOptions: mutationObserverOptions ?? defaultMutationObserverOptions, + mutationObserverOptions: mutationObserverOptions, ); } @@ -313,9 +313,9 @@ mixin ByTextQueries on IQueries { String? selector, /*String|bool*/ dynamic ignore = 'script', Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, - MutationObserverOptions? mutationObserverOptions, + MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getAllByText` instead of an // interop like `_jsFindAllByText` to give consumers better async stack traces. @@ -329,9 +329,9 @@ mixin ByTextQueries on IQueries { ), container: getContainerForScope(), timeout: timeout, - interval: interval ?? defaultAsyncCallbackCheckInterval, + interval: interval, onTimeout: onTimeout, - mutationObserverOptions: mutationObserverOptions ?? defaultMutationObserverOptions, + mutationObserverOptions: mutationObserverOptions, ); } } diff --git a/lib/src/dom/queries/by_title.dart b/lib/src/dom/queries/by_title.dart index c6064abd..52e40d18 100644 --- a/lib/src/dom/queries/by_title.dart +++ b/lib/src/dom/queries/by_title.dart @@ -240,9 +240,9 @@ mixin ByTitleQueries on IQueries { bool exact = true, NormalizerFn Function([NormalizerOptions?])? normalizer, Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, - MutationObserverOptions? mutationObserverOptions, + MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getByTitle` instead of an // interop like `_jsFindByTitle` to give consumers better async stack traces. @@ -254,9 +254,9 @@ mixin ByTitleQueries on IQueries { ), container: getContainerForScope(), timeout: timeout, - interval: interval ?? defaultAsyncCallbackCheckInterval, + interval: interval, onTimeout: onTimeout, - mutationObserverOptions: mutationObserverOptions ?? defaultMutationObserverOptions, + mutationObserverOptions: mutationObserverOptions, ); } @@ -295,9 +295,9 @@ mixin ByTitleQueries on IQueries { bool exact = true, NormalizerFn Function([NormalizerOptions?])? normalizer, Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, - MutationObserverOptions? mutationObserverOptions, + MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) { // NOTE: Using our own Dart `waitFor` as a wrapper around `getAllByTitle` instead of an // interop like `_jsFindAllByTitle` to give consumers better async stack traces. @@ -309,9 +309,9 @@ mixin ByTitleQueries on IQueries { ), container: getContainerForScope(), timeout: timeout, - interval: interval ?? defaultAsyncCallbackCheckInterval, + interval: interval, onTimeout: onTimeout, - mutationObserverOptions: mutationObserverOptions ?? defaultMutationObserverOptions, + mutationObserverOptions: mutationObserverOptions, ); } } diff --git a/lib/src/dom/queries/interface.dart b/lib/src/dom/queries/interface.dart index 5cde462c..b7295e7d 100644 --- a/lib/src/dom/queries/interface.dart +++ b/lib/src/dom/queries/interface.dart @@ -53,6 +53,7 @@ mixin IQueries { if (timeout != null) waitForOptions.timeout = timeout.inMilliseconds; if (interval != null) waitForOptions.interval = interval.inMilliseconds; if (onTimeout != null) waitForOptions.onTimeout = allowInterop(onTimeout); + // ignore: invalid_use_of_protected_member waitForOptions.mutationObserverOptions = mutationObserverOptions.toJs(); return waitForOptions; diff --git a/lib/src/dom/top_level_queries.dart b/lib/src/dom/top_level_queries.dart index e51b558b..3dc7b15e 100644 --- a/lib/src/dom/top_level_queries.dart +++ b/lib/src/dom/top_level_queries.dart @@ -16,7 +16,7 @@ import 'dart:html' show AreaElement, Element, ImageElement, InputElement, LabelElement, Node, SelectElement, TextAreaElement; import 'package:react_testing_library/src/dom/async/types.dart' - show MutationObserverOptions, QueryTimeoutFn, defaultMutationObserverOptions; + show MutationObserverOptions, QueryTimeoutFn, defaultAsyncCallbackCheckInterval, defaultMutationObserverOptions; import 'package:react_testing_library/src/dom/matches/types.dart' show NormalizerFn, NormalizerOptions; import 'package:react_testing_library/src/dom/within.dart' show within; @@ -193,7 +193,7 @@ Future findByAltText( bool exact = true, NormalizerFn Function([NormalizerOptions?])? normalizer, Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => @@ -246,7 +246,7 @@ Future> findAllByAltText( bool exact = true, NormalizerFn Function([NormalizerOptions?])? normalizer, Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => @@ -430,7 +430,7 @@ Future findByDisplayValue( bool exact = true, NormalizerFn Function([NormalizerOptions?])? normalizer, Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => @@ -482,7 +482,7 @@ Future> findAllByDisplayValue( bool exact = true, NormalizerFn Function([NormalizerOptions?])? normalizer, Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => @@ -666,7 +666,7 @@ Future findByLabelText( NormalizerFn Function([NormalizerOptions?])? normalizer, String? selector, Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => @@ -719,7 +719,7 @@ Future> findAllByLabelText( NormalizerFn Function([NormalizerOptions?])? normalizer, String? selector, Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => @@ -904,7 +904,7 @@ Future findByPlaceholderText( bool exact = true, NormalizerFn Function([NormalizerOptions?])? normalizer, Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => @@ -956,7 +956,7 @@ Future> findAllByPlaceholderText( bool exact = true, NormalizerFn Function([NormalizerOptions?])? normalizer, Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => @@ -1248,7 +1248,7 @@ Future findByRole( bool queryFallbacks = false, int? level, Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => @@ -1323,7 +1323,7 @@ Future> findAllByRole( bool queryFallbacks = false, int? level, Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => @@ -1515,7 +1515,7 @@ Future findByTestId( bool exact = true, NormalizerFn Function([NormalizerOptions?])? normalizer, Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => @@ -1567,7 +1567,7 @@ Future> findAllByTestId( bool exact = true, NormalizerFn Function([NormalizerOptions?])? normalizer, Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => @@ -1767,7 +1767,7 @@ Future findByText( String? selector, /*String|bool*/ dynamic ignore = 'script', Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => @@ -1825,7 +1825,7 @@ Future> findAllByText( String? selector, /*String|bool*/ dynamic ignore = 'script', Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => @@ -2011,7 +2011,7 @@ Future findByTitle( bool exact = true, NormalizerFn Function([NormalizerOptions?])? normalizer, Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => @@ -2063,7 +2063,7 @@ Future> findAllByTitle( bool exact = true, NormalizerFn Function([NormalizerOptions?])? normalizer, Duration? timeout, - Duration? interval, + Duration interval = defaultAsyncCallbackCheckInterval, QueryTimeoutFn? onTimeout, MutationObserverOptions mutationObserverOptions = defaultMutationObserverOptions, }) => From 07a008ffa8523cb439c8dda4bf387d48db351071 Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Tue, 21 Nov 2023 11:18:19 -0700 Subject: [PATCH 28/31] Update within --- lib/src/dom/async/types.dart | 1 - lib/src/dom/within.dart | 10 +++---- test/unit/dom/queries/by_role_test.dart | 36 ++++++++++++------------- 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/lib/src/dom/async/types.dart b/lib/src/dom/async/types.dart index b2d12793..ef40a56c 100644 --- a/lib/src/dom/async/types.dart +++ b/lib/src/dom/async/types.dart @@ -17,7 +17,6 @@ library react_testing_library.src.dom.async.types; import 'package:js/js.dart'; import 'package:meta/meta.dart'; -import 'package:react_testing_library/src/dom/config/configure.dart' show getConfig; /// A function typedef used by `onTimeout` parameters in asynchronous `find*` / `waitFor` queries. /// diff --git a/lib/src/dom/within.dart b/lib/src/dom/within.dart index c793922c..f1a35b95 100644 --- a/lib/src/dom/within.dart +++ b/lib/src/dom/within.dart @@ -22,7 +22,6 @@ import 'package:meta/meta.dart'; import 'package:react_testing_library/src/dom/pretty_dom.dart'; import 'package:react_testing_library/src/dom/scoped_queries.dart' show ScopedQueries; import 'package:react_testing_library/src/util/console_log_utils.dart'; -import 'package:react_testing_library/src/util/is_or_contains.dart'; /// Queries scoped to the provided [container]. /// @@ -48,12 +47,11 @@ class WithinQueries extends ScopedQueries { /// > See: /// /// {@category Queries} -WithinQueries within(Node? node) { - if (node == null) { - throw ArgumentError.notNull('node'); - } +WithinQueries within(Node node) { + // Keep null check to maintain backwards compatibility for consumers that are not opted in to null safety. + ArgumentError.checkNotNull(node); - if (node is! ShadowRoot && !isOrContains(document.body!, node)) { + if (node is! ShadowRoot && !(node.isConnected ?? false)) { throw ArgumentError.value( node, 'node', diff --git a/test/unit/dom/queries/by_role_test.dart b/test/unit/dom/queries/by_role_test.dart index b6943a11..98a9487c 100644 --- a/test/unit/dom/queries/by_role_test.dart +++ b/test/unit/dom/queries/by_role_test.dart @@ -266,7 +266,7 @@ void main() { }); test('[no match]', () { - expect(rtl.within(emptyElementRef.current).queryByRole('checkbox', checked: true), isNull); + expect(rtl.within(emptyElementRef.current!).queryByRole('checkbox', checked: true), isNull); }); }); @@ -277,7 +277,7 @@ void main() { }); test('[no matches]', () { - expect(rtl.within(emptyElementRef.current).queryAllByRole('checkbox', checked: true), isEmpty); + expect(rtl.within(emptyElementRef.current!).queryAllByRole('checkbox', checked: true), isEmpty); }); }); @@ -288,7 +288,7 @@ void main() { test('[no match]', () { expect( - () => rtl.within(emptyElementRef.current).getByRole('checkbox', checked: true), + () => rtl.within(emptyElementRef.current!).getByRole('checkbox', checked: true), throwsA(allOf( isA(), hasToStringValue(contains('Unable to find an accessible element with the role "checkbox"')), @@ -307,7 +307,7 @@ void main() { test('[no matches]', () { expect( - () => rtl.within(emptyElementRef.current).getAllByRole('checkbox', checked: true), + () => rtl.within(emptyElementRef.current!).getAllByRole('checkbox', checked: true), throwsA(allOf( isA(), hasToStringValue(contains('Unable to find an accessible element with the role "checkbox"')), @@ -325,7 +325,7 @@ void main() { test('[no match]', () async { expect( - () => rtl.within(emptyElementRef.current).findByRole('checkbox', checked: true), + () => rtl.within(emptyElementRef.current!).findByRole('checkbox', checked: true), throwsA(allOf( isA(), hasToStringValue(contains('Unable to find an accessible element with the role "checkbox"')), @@ -344,7 +344,7 @@ void main() { test('[no matches]', () async { expect( - () => rtl.within(emptyElementRef.current).findAllByRole('checkbox', checked: true), + () => rtl.within(emptyElementRef.current!).findAllByRole('checkbox', checked: true), throwsA(allOf( isA(), hasToStringValue(contains('Unable to find an accessible element with the role "checkbox"')), @@ -366,7 +366,7 @@ void main() { }); test('[no match]', () { - expect(rtl.within(emptyElementRef.current).queryByRole('button', pressed: true), isNull); + expect(rtl.within(emptyElementRef.current!).queryByRole('button', pressed: true), isNull); }); }); @@ -377,7 +377,7 @@ void main() { }); test('[no matches]', () { - expect(rtl.within(emptyElementRef.current).queryAllByRole('button', pressed: true), isEmpty); + expect(rtl.within(emptyElementRef.current!).queryAllByRole('button', pressed: true), isEmpty); }); }); @@ -388,7 +388,7 @@ void main() { test('[no match]', () { expect( - () => rtl.within(emptyElementRef.current).getByRole('button', pressed: true), + () => rtl.within(emptyElementRef.current!).getByRole('button', pressed: true), throwsA(allOf( isA(), hasToStringValue(contains('Unable to find an accessible element with the role "button"')), @@ -407,7 +407,7 @@ void main() { test('[no matches]', () { expect( - () => rtl.within(emptyElementRef.current).getAllByRole('button', pressed: true), + () => rtl.within(emptyElementRef.current!).getAllByRole('button', pressed: true), throwsA(allOf( isA(), hasToStringValue(contains('Unable to find an accessible element with the role "button"')), @@ -425,7 +425,7 @@ void main() { test('[no match]', () async { expect( - () => rtl.within(emptyElementRef.current).findByRole('button', pressed: true), + () => rtl.within(emptyElementRef.current!).findByRole('button', pressed: true), throwsA(allOf( isA(), hasToStringValue(contains('Unable to find an accessible element with the role "button"')), @@ -444,7 +444,7 @@ void main() { test('[no matches]', () async { expect( - () => rtl.within(emptyElementRef.current).findAllByRole('button', pressed: true), + () => rtl.within(emptyElementRef.current!).findAllByRole('button', pressed: true), throwsA(allOf( isA(), hasToStringValue(contains('Unable to find an accessible element with the role "button"')), @@ -563,7 +563,7 @@ void main() { }); test('[no match]', () { - expect(rtl.within(emptyElementRef.current).queryByRole('heading', level: 2), isNull); + expect(rtl.within(emptyElementRef.current!).queryByRole('heading', level: 2), isNull); }); }); @@ -574,7 +574,7 @@ void main() { }); test('[no matches]', () { - expect(rtl.within(emptyElementRef.current).queryAllByRole('heading', level: 2), isEmpty); + expect(rtl.within(emptyElementRef.current!).queryAllByRole('heading', level: 2), isEmpty); }); }); @@ -585,7 +585,7 @@ void main() { test('[no match]', () { expect( - () => rtl.within(emptyElementRef.current).getByRole('heading', level: 2), + () => rtl.within(emptyElementRef.current!).getByRole('heading', level: 2), throwsA(allOf( isA(), hasToStringValue(contains('Unable to find an accessible element with the role "heading"')), @@ -604,7 +604,7 @@ void main() { test('[no matches]', () { expect( - () => rtl.within(emptyElementRef.current).getAllByRole('heading', level: 2), + () => rtl.within(emptyElementRef.current!).getAllByRole('heading', level: 2), throwsA(allOf( isA(), hasToStringValue(contains('Unable to find an accessible element with the role "heading"')), @@ -622,7 +622,7 @@ void main() { test('[no match]', () async { expect( - () => rtl.within(emptyElementRef.current).findByRole('heading', level: 2), + () => rtl.within(emptyElementRef.current!).findByRole('heading', level: 2), throwsA(allOf( isA(), hasToStringValue(contains('Unable to find an accessible element with the role "heading"')), @@ -641,7 +641,7 @@ void main() { test('[no matches]', () async { expect( - () => rtl.within(emptyElementRef.current).findAllByRole('heading', level: 2), + () => rtl.within(emptyElementRef.current!).findAllByRole('heading', level: 2), throwsA(allOf( isA(), hasToStringValue(contains('Unable to find an accessible element with the role "heading"')), From 42410ab89ccec2f435815c6078f7c9c0d62450e2 Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Tue, 21 Nov 2023 15:30:36 -0700 Subject: [PATCH 29/31] Update matchers --- lib/src/matchers/jest_dom/css_class_matchers.dart | 11 ++++++++--- lib/src/matchers/jest_dom/has_form_values.dart | 7 +++++-- lib/src/matchers/jest_dom/is_checked.dart | 4 ++-- .../util/element_text_content_matcher_mixin.dart | 2 +- lib/src/matchers/jest_dom/util/get_value_of.dart | 8 ++++++-- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/src/matchers/jest_dom/css_class_matchers.dart b/lib/src/matchers/jest_dom/css_class_matchers.dart index 4c8e2c1b..95e5eee7 100644 --- a/lib/src/matchers/jest_dom/css_class_matchers.dart +++ b/lib/src/matchers/jest_dom/css_class_matchers.dart @@ -232,17 +232,22 @@ class _ClassNameMatcher extends Matcher { @override Description describeMismatch(dynamic item, Description mismatchDescription, Map matchState, bool verbose) { - final missingClasses = matchState['missingClasses'] as Set; + final missingClasses = matchState['missingClasses'] as Set?; final unwantedClasses = matchState['unwantedClasses'] as Set?; final extraneousClasses = matchState['extraneousClasses'] as List?; + if (missingClasses == null || unwantedClasses == null || extraneousClasses == null) { + throw ArgumentError( + '`matchState` should have the following keys: "missingClasses", "unwantedClasses", "extraneousClasses"'); + } + final descriptionParts = []; if (allowExtraneous) { - if (unwantedClasses!.isNotEmpty) { + if (unwantedClasses.isNotEmpty) { descriptionParts.add('has unwanted classes: $unwantedClasses'); } } else { - if (extraneousClasses!.isNotEmpty) { + if (extraneousClasses.isNotEmpty) { descriptionParts.add('has extraneous classes: $extraneousClasses'); } } diff --git a/lib/src/matchers/jest_dom/has_form_values.dart b/lib/src/matchers/jest_dom/has_form_values.dart index 82f18dbb..7a73f27a 100644 --- a/lib/src/matchers/jest_dom/has_form_values.dart +++ b/lib/src/matchers/jest_dom/has_form_values.dart @@ -175,6 +175,9 @@ JsObject _getJsFormOrFieldSet(Element form) => JsObject.fromBrowserObject(form); /// /// Wraps the [HTMLFormElement.elements](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/elements) property. List getFormElements(Element form) { - assert(form is FormElement || form is FieldSetElement); - return convertToArray(_getJsFormOrFieldSet(form)['elements'] as JsObject?); + final elements = _getJsFormOrFieldSet(form)['elements'] as JsObject?; + if ((form is! FormElement && form is! FieldSetElement) || elements == null) { + throw ArgumentError('should be a form or fieldset element with the elements property', 'form'); + } + return convertToArray(elements); } diff --git a/lib/src/matchers/jest_dom/is_checked.dart b/lib/src/matchers/jest_dom/is_checked.dart index fc43feb1..572c0f72 100644 --- a/lib/src/matchers/jest_dom/is_checked.dart +++ b/lib/src/matchers/jest_dom/is_checked.dart @@ -94,6 +94,8 @@ class _IsChecked extends Matcher { item != null && matchState['isElement'] as bool && matchState['canBeChecked'] as bool; bool isElementChecked(Element item, Map matchState) { + if (!isElementThatCanBeChecked(item, matchState)) return false; + if (item is InputElement) { final type = item.getAttribute('type'); if (_validTypes.contains(type)) { @@ -122,8 +124,6 @@ class _IsChecked extends Matcher { bool matches(dynamic item, Map matchState) { setMatchState(item, matchState); - if (!isElementThatCanBeChecked(item, matchState)) return false; - return isElementChecked(item as Element, matchState); } diff --git a/lib/src/matchers/jest_dom/util/element_text_content_matcher_mixin.dart b/lib/src/matchers/jest_dom/util/element_text_content_matcher_mixin.dart index 0e4fbab0..22609753 100644 --- a/lib/src/matchers/jest_dom/util/element_text_content_matcher_mixin.dart +++ b/lib/src/matchers/jest_dom/util/element_text_content_matcher_mixin.dart @@ -22,7 +22,7 @@ mixin ElementTextContentMatcherMixin on CustomMatcher { if (item is! Element) return null; if (!normalizeWhitespace) return item.text; - return item.text!.replaceAll(RegExp(r'\s+'), ' '); + return item.text?.replaceAll(RegExp(r'\s+'), ' '); } /// Returns a normalized [String] or [Matcher] based on the provided [userExpectedTextContent] diff --git a/lib/src/matchers/jest_dom/util/get_value_of.dart b/lib/src/matchers/jest_dom/util/get_value_of.dart index 62222d49..222b10cb 100644 --- a/lib/src/matchers/jest_dom/util/get_value_of.dart +++ b/lib/src/matchers/jest_dom/util/get_value_of.dart @@ -36,12 +36,16 @@ dynamic getValueOf(Element element, {dynamic Function(OptionElement option)? get } } else if (element is SelectElement) { getOptionValue ??= (option) => option.value; + final multiple = element.multiple; + if (multiple == null) { + throw ArgumentError('If `element` is a `SelectElement`, it should always have the `multiple` property set.'); + } final selectedOptions = element.options.where((option) => option.selected); if (selectedOptions.isEmpty) { - return element.multiple! ? const [] : null; + return multiple ? const [] : null; } else if (selectedOptions.length == 1) { final selectedValues = selectedOptions.map(getOptionValue); - return element.multiple! ? selectedValues.toList() : selectedValues.single; + return multiple ? selectedValues.toList() : selectedValues.single; } else { return selectedOptions.map(getOptionValue).toList(); } From 17a41cfedfb6c5c7acbebebe883a9eef3881a9e9 Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Tue, 21 Nov 2023 16:19:25 -0700 Subject: [PATCH 30/31] Clean up other utils --- lib/src/react/render/types.dart | 16 ++++++------ lib/src/user_event/user_event.dart | 35 ++++++++++++++++++--------- lib/src/util/error_message_utils.dart | 10 +++++--- lib/src/util/js_utils.dart | 2 +- 4 files changed, 40 insertions(+), 23 deletions(-) diff --git a/lib/src/react/render/types.dart b/lib/src/react/render/types.dart index be4d5365..5b4f9b05 100644 --- a/lib/src/react/render/types.dart +++ b/lib/src/react/render/types.dart @@ -51,18 +51,18 @@ class JsRenderResult { @JS() @anonymous class RenderOptions { - external Node get container; - external set container(Node value); + external Node? get container; + external set container(Node? value); - external Node get baseElement; - external set baseElement(Node value); + external Node? get baseElement; + external set baseElement(Node? value); external dynamic get wrapper; external set wrapper(dynamic value); - external bool get hydrate; - external set hydrate(bool value); + external bool? get hydrate; + external set hydrate(bool? value); - external JsMap get queries; - external set queries(JsMap value); + external JsMap? get queries; + external set queries(JsMap? value); } diff --git a/lib/src/user_event/user_event.dart b/lib/src/user_event/user_event.dart index c57e14a7..412a0b7d 100644 --- a/lib/src/user_event/user_event.dart +++ b/lib/src/user_event/user_event.dart @@ -111,7 +111,7 @@ abstract class UserEvent { /// {@category UserActions} static void click( Element element, { - Map? eventInit, + Map eventInit = const {}, bool skipHover = false, int clickCount = 0, bool skipPointerEventsCheck = false, @@ -200,7 +200,11 @@ abstract class UserEvent { /// {@macro RenderSupportsReactAndOverReactCallout} /// /// {@category UserActions} - static void dblClick(Element element, {Map? eventInit, bool skipPointerEventsCheck = false}) { + static void dblClick( + Element element, { + Map eventInit = const {}, + bool skipPointerEventsCheck = false, + }) { final options = { 'skipPointerEventsCheck': skipPointerEventsCheck, }; @@ -440,6 +444,7 @@ abstract class UserEvent { element, text, jsifyAndAllowInterop(options), + // Cast return type of JS function to be compatible with `promiseToFuture`. ) as Object); }); } @@ -631,6 +636,7 @@ abstract class UserEvent { return promiseToFuture(getProperty(_userEvent, 'keyboard')( text, jsifyAndAllowInterop(options), + // Cast return type of JS function to be compatible with `promiseToFuture`. ) as Object); }); } @@ -749,8 +755,8 @@ abstract class UserEvent { static void upload( /*InputElement | LabelElement*/ Element element, List files, { - Map? clickInit, - Map? changeInit, + Map clickInit = const {}, + Map changeInit = const {}, bool applyAccept = false, }) { final init = { @@ -911,7 +917,7 @@ abstract class UserEvent { static void selectOptions( SelectElement selectElement, List values, { - Map? clickInit, + Map clickInit = const {}, bool skipPointerEventsCheck = false, }) { final options = { @@ -1014,7 +1020,7 @@ abstract class UserEvent { static void deselectOptions( SelectElement selectElement, List values, { - Map? clickInit, + Map clickInit = const {}, bool skipPointerEventsCheck = false, }) { final options = { @@ -1123,7 +1129,10 @@ abstract class UserEvent { /// /// {@category UserActions} static void tab({bool shift = false, Element? focusTrap}) { - final options = {'shift': shift, 'focusTrap': focusTrap}; + final options = { + 'shift': shift, + if (focusTrap != null) 'focusTrap': focusTrap, + }; eventHandlerErrorCatcher(() { getProperty(_userEvent, 'tab')( jsifyAndAllowInterop(options), @@ -1210,7 +1219,7 @@ abstract class UserEvent { /// {@category UserActions} static void hover( Element element, { - Map? eventInit, + Map eventInit = const {}, bool skipPointerEventsCheck = false, }) { final options = { @@ -1309,7 +1318,11 @@ abstract class UserEvent { /// {@macro RenderSupportsReactAndOverReactCallout} /// /// {@category UserActions} - static void unhover(Element element, {Map? eventInit, bool skipPointerEventsCheck = false}) { + static void unhover( + Element element, { + Map eventInit = const {}, + bool skipPointerEventsCheck = false, + }) { final options = { 'skipPointerEventsCheck': skipPointerEventsCheck, }; @@ -1390,7 +1403,7 @@ abstract class UserEvent { static void paste( Element element, String text, { - Map? eventInit, + Map eventInit = const {}, int? initialSelectionStart, int? initialSelectionEnd, }) { @@ -1420,7 +1433,7 @@ class KeyboardState { external factory KeyboardState._(); } -dynamic _jsifyEventData(Map? eventData) => jsifyAndAllowInterop(eventData ?? const {}); +dynamic _jsifyEventData(Map eventData) => jsifyAndAllowInterop(eventData); // Converts a JsMap FileList to a List. List _unjsifyFileList(List? fileList) { diff --git a/lib/src/util/error_message_utils.dart b/lib/src/util/error_message_utils.dart index cc0c93e8..160313f9 100644 --- a/lib/src/util/error_message_utils.dart +++ b/lib/src/util/error_message_utils.dart @@ -53,7 +53,11 @@ class TestingLibraryElementError extends Error { TestingLibraryElementError(this.message, [this.jsStackTrace]) : super(); factory TestingLibraryElementError.fromJs(/*JsError*/ dynamic jsError, [StackTrace? jsStackTrace]) { - final stack = jsError is JsError ? jsStackTrace ?? StackTrace.fromString(jsError.stack) : null; + StackTrace? stack; + if (jsError is JsError) { + final jsErrorStack = jsError.stack; + stack = jsStackTrace ?? (jsErrorStack != null ? StackTrace.fromString(jsErrorStack) : null); + } return TestingLibraryElementError(jsError.toString(), stack); } @@ -76,8 +80,8 @@ class JsError { external String get message; external set message(String value); - external String get stack; - external set stack(String value); + external String? get stack; + external set stack(String? value); } @JS('rtl.buildJsGetElementError') diff --git a/lib/src/util/js_utils.dart b/lib/src/util/js_utils.dart index 46fcf465..be49d572 100644 --- a/lib/src/util/js_utils.dart +++ b/lib/src/util/js_utils.dart @@ -23,7 +23,7 @@ final jsArray = context['Array'] as JsObject; final arrayProtoSlice = jsArray['prototype']['slice'] as JsObject; /// Converts the Array-like [object] to a [JsArray] using [arrayProtoSlice]. -JsArray convertToArray(JsObject? object) { +JsArray convertToArray(JsObject object) { final rawArray = (arrayProtoSlice.callMethod('apply', [object]) as Iterable).cast(); return JsArray.from(rawArray); } From 6bc076722d9e169dcb003488f64ec0fa8f3b5aa9 Mon Sep 17 00:00:00 2001 From: Sydney Jodon Date: Tue, 28 Nov 2023 13:16:43 -0700 Subject: [PATCH 31/31] Address feedback --- lib/src/dom/matches/types.dart | 4 +- .../matchers/jest_dom/has_form_values.dart | 9 ++-- lib/src/user_event/user_event.dart | 13 +++--- lib/src/util/console_log_formatter.dart | 6 +-- lib/src/util/error_message_utils.dart | 6 +-- .../dom/matchers/has_form_values_test.dart | 44 +++++++++++------- test/unit/dom/matchers/has_value_test.dart | 38 +++++++++------- test/unit/dom/queries/by_testid_test.dart | 6 ++- test/unit/dom/queries/by_text_test.dart | 6 ++- test/unit/dom/top_level_queries_test.dart | 45 ++++++++++--------- test/unit/dom/wait_for_test.dart | 8 ++-- test/unit/util/matchers.dart | 4 +- 12 files changed, 107 insertions(+), 82 deletions(-) diff --git a/lib/src/dom/matches/types.dart b/lib/src/dom/matches/types.dart index 447213e7..d296c23f 100644 --- a/lib/src/dom/matches/types.dart +++ b/lib/src/dom/matches/types.dart @@ -75,8 +75,8 @@ abstract class TextMatch { /// /// And instead, they see the [newValue] provided - which should contain a more helpful message that includes /// the value they provided as the `TextMatch` argument. - static Object Function(Object originalMessage, Element container) _replaceDartInteropFunctionStringWith( - Object newValue) { + static Object? Function(Object? originalMessage, Element container) _replaceDartInteropFunctionStringWith( + Object? newValue) { final dartInteropFunctionValueRegex = RegExp(r'([\"`]*)(function[\s\S]+})([\"`]*)(.*)([\s\S]+)*', multiLine: true); return (originalMessage, container) { diff --git a/lib/src/matchers/jest_dom/has_form_values.dart b/lib/src/matchers/jest_dom/has_form_values.dart index 7a73f27a..a8f8b807 100644 --- a/lib/src/matchers/jest_dom/has_form_values.dart +++ b/lib/src/matchers/jest_dom/has_form_values.dart @@ -15,7 +15,6 @@ import 'dart:html'; import 'dart:js'; -import 'package:collection/collection.dart' show IterableExtension; import 'package:matcher/matcher.dart'; import 'package:react_testing_library/dom/debugging.dart'; import 'package:react_testing_library/src/matchers/jest_dom/util/constants.dart'; @@ -128,10 +127,10 @@ class _HasFormValues extends CustomMatcher { } break; case 'radio': - final allRadiosWithName = element.querySelectorAll('input[type="radio"][name="$childElementName"]'); - final selectedRadioElement = allRadiosWithName.singleWhereOrNull( - (radioEl) => (radioEl as RadioButtonInputElement).checked!, - ) as RadioButtonInputElement?; + final allRadiosWithName = + element.querySelectorAll('input[type="radio"][name="$childElementName"]'); + final selectedRadioElements = allRadiosWithName.where((radioEl) => radioEl.checked!).toList(); + final selectedRadioElement = selectedRadioElements.isEmpty ? null : selectedRadioElements.single; actualNamesAndValues[elementNameToTest] = selectedRadioElement?.value; break; default: diff --git a/lib/src/user_event/user_event.dart b/lib/src/user_event/user_event.dart index 412a0b7d..450e128e 100644 --- a/lib/src/user_event/user_event.dart +++ b/lib/src/user_event/user_event.dart @@ -777,9 +777,9 @@ abstract class UserEvent { // map with with an `item` method to access files. final control = element is LabelElement ? element.control : null; if (control is InputElement) { - control.files = _unjsifyFileList(control.files); + control.files = _unjsifyFileList(control.files ?? []); } else if (element is FileUploadInputElement) { - element.files = _unjsifyFileList(element.files); + element.files = _unjsifyFileList(element.files ?? []); } } @@ -1436,16 +1436,13 @@ class KeyboardState { dynamic _jsifyEventData(Map eventData) => jsifyAndAllowInterop(eventData); // Converts a JsMap FileList to a List. -List _unjsifyFileList(List? fileList) { +List _unjsifyFileList(List fileList) { if (fileList is FileList) return fileList; - final jsFileList = JsBackedMap.fromJs((fileList ?? []) as JsMap); + final jsFileList = JsBackedMap.fromJs(fileList as JsMap); final convertedFiles = []; for (var i = 0; i < (jsFileList['length'] as int); i++) { - final file = jsFileList['item'](i); - if (file is File) { - convertedFiles.add(file); - } + convertedFiles.add(jsFileList['item'](i) as File); } return convertedFiles; } diff --git a/lib/src/util/console_log_formatter.dart b/lib/src/util/console_log_formatter.dart index e97292f6..91b89264 100644 --- a/lib/src/util/console_log_formatter.dart +++ b/lib/src/util/console_log_formatter.dart @@ -50,9 +50,9 @@ String format(dynamic f, List arguments) { var i = 0; final len = arguments.length; str += f.replaceAllMapped(_formatRegExp, (m) { - final x = m[0]; + final x = m[0]!; if (x == '%%') return '%'; - if (i >= len) return x!; + if (i >= len) return x; switch (x) { case '%s': return arguments[i++].toString(); @@ -70,7 +70,7 @@ String format(dynamic f, List arguments) { return '[Circular]'; } default: - return x!; + return x; } }); diff --git a/lib/src/util/error_message_utils.dart b/lib/src/util/error_message_utils.dart index 160313f9..afba156d 100644 --- a/lib/src/util/error_message_utils.dart +++ b/lib/src/util/error_message_utils.dart @@ -24,11 +24,11 @@ import 'package:react_testing_library/src/dom/config/configure.dart' show config /// Builds and configures react-testing-library to use a custom value for `JsConfig.getElementError` /// if any queries fail in the current test. void setEphemeralElementErrorMessage( - Object Function(Object originalMessage, Element container) customErrorMessageBuilder, + Object? Function(Object? originalMessage, Element container) customErrorMessageBuilder, {StackTrace? jsStackTrace}) { TestingLibraryElementError buildCustomDartGetElementError(Object? originalMessage, Element container) { return TestingLibraryElementError.fromJs( - buildJsGetElementError(customErrorMessageBuilder(originalMessage ?? '', container), container), jsStackTrace); + buildJsGetElementError(customErrorMessageBuilder(originalMessage, container), container), jsStackTrace); } configure(getElementError: buildCustomDartGetElementError); @@ -85,4 +85,4 @@ class JsError { } @JS('rtl.buildJsGetElementError') -external JsError buildJsGetElementError(Object message, Element container); +external JsError buildJsGetElementError(Object? message, Element container); diff --git a/test/unit/dom/matchers/has_form_values_test.dart b/test/unit/dom/matchers/has_form_values_test.dart index a890656f..d240d1c6 100644 --- a/test/unit/dom/matchers/has_form_values_test.dart +++ b/test/unit/dom/matchers/has_form_values_test.dart @@ -53,8 +53,6 @@ void main() { return render(vDom); } - late RenderResult view; - group('passes when provided with a valid name/value combination for a', () { final unTestedChildFormElemThatShouldNotCauseFailure = _FormElemDefinition(react.input, { 'type': 'text', @@ -64,6 +62,8 @@ void main() { }); group('TextInputElement', () { + late RenderResult view; + setUp(() { view = renderFormWithValues(react.form, [ _FormElemDefinition(react.input, { @@ -92,6 +92,8 @@ void main() { }); group('TextAreaElement', () { + late RenderResult view; + setUp(() { view = renderFormWithValues(react.form, [ _FormElemDefinition( @@ -116,6 +118,8 @@ void main() { }); group('NumberInputElement', () { + late RenderResult view; + setUp(() { view = renderFormWithValues(react.form, [ _FormElemDefinition(react.input, { @@ -138,7 +142,7 @@ void main() { group('CheckboxInputElement', () { test('when each has a unique name', () { - view = renderFormWithValues(react.form, [ + final view = renderFormWithValues(react.form, [ _FormElemDefinition(react.input, { 'type': 'checkbox', 'name': 'business-in-front', @@ -168,6 +172,8 @@ void main() { }); group('when they have the same names', () { + late RenderResult view; + setUp(() { view = renderFormWithValues(react.form, [ _FormElemDefinition(react.input, { @@ -232,6 +238,8 @@ void main() { }); group('RadioInputElement', () { + late RenderResult view; + setUp(() { view = renderFormWithValues(react.form, [ _FormElemDefinition(react.input, { @@ -262,7 +270,7 @@ void main() { group('when only a single option can be selected', () { group('and a single option is selected', () { test('exact match', () { - view = renderFormWithValues(react.form, [ + final view = renderFormWithValues(react.form, [ _FormElemDefinition(react.select, { 'name': 'account-type', 'defaultValue': 'business', @@ -287,7 +295,7 @@ void main() { }); test('using a matcher', () { - view = renderFormWithValues(react.form, [ + final view = renderFormWithValues(react.form, [ _FormElemDefinition(react.select, { 'name': 'account-type', }, [ @@ -312,7 +320,7 @@ void main() { }); test('and no option is selected', () { - view = renderFormWithValues(react.form, [ + final view = renderFormWithValues(react.form, [ _FormElemDefinition(react.select, { 'name': 'account-type', }, [ @@ -340,6 +348,8 @@ void main() { group('when multiple options can be selected', () { group('and a single option is selected', () { + late RenderResult view; + setUp(() { view = renderFormWithValues(react.form, [ _FormElemDefinition(react.select, { @@ -384,6 +394,8 @@ void main() { }); group('and multiple options are selected', () { + late RenderResult view; + setUp(() { view = renderFormWithValues(react.form, [ _FormElemDefinition(react.select, { @@ -428,7 +440,7 @@ void main() { }); test('and no option is selected', () { - view = renderFormWithValues(react.form, [ + final view = renderFormWithValues(react.form, [ _FormElemDefinition(react.select, { 'name': 'pizza-toppings', 'multiple': true, @@ -490,7 +502,7 @@ void main() { } test('element which has a name not used as a key in the provided map', () { - view = renderFormWithValues(react.form, [ + final view = renderFormWithValues(react.form, [ _FormElemDefinition(react.input, { 'type': 'text', 'name': 'firstName', @@ -508,7 +520,7 @@ void main() { group('which has a name found in the provided map, but different value(s):', () { test('TextInputElement', () { - view = renderFormWithValues(react.form, [ + final view = renderFormWithValues(react.form, [ _FormElemDefinition(react.input, { 'type': 'text', 'name': 'firstName', @@ -525,7 +537,7 @@ void main() { }); test('TextAreaElement', () { - view = renderFormWithValues(react.form, [ + final view = renderFormWithValues(react.form, [ _FormElemDefinition(react.textarea, { 'name': 'comments', 'defaultValue': 'I have nothing nice to say', @@ -543,7 +555,7 @@ void main() { }); test('NumberInputElement', () { - view = renderFormWithValues(react.form, [ + final view = renderFormWithValues(react.form, [ _FormElemDefinition(react.input, { 'type': 'number', 'name': 'age', @@ -561,7 +573,7 @@ void main() { group('CheckboxInputElement', () { test('when each has a unique name', () { - view = renderFormWithValues(react.form, [ + final view = renderFormWithValues(react.form, [ _FormElemDefinition(react.input, { 'type': 'checkbox', 'name': 'business-in-front', @@ -590,7 +602,7 @@ void main() { }); test('when they have the same names', () { - view = renderFormWithValues(react.form, [ + final view = renderFormWithValues(react.form, [ _FormElemDefinition(react.input, { 'type': 'checkbox', 'name': 'pizza-toppings', @@ -654,7 +666,7 @@ void main() { }); test('RadioInputElement', () { - view = renderFormWithValues(react.form, [ + final view = renderFormWithValues(react.form, [ _FormElemDefinition(react.input, { 'type': 'radio', 'name': 'account-type', @@ -679,7 +691,7 @@ void main() { group('SelectElement', () { test('when only a single option can be selected', () { - view = renderFormWithValues(react.form, [ + final view = renderFormWithValues(react.form, [ _FormElemDefinition(react.select, { 'name': 'account-type', 'defaultValue': 'business', @@ -705,7 +717,7 @@ void main() { }); test('when multiple options can be selected', () { - view = renderFormWithValues(react.form, [ + final view = renderFormWithValues(react.form, [ _FormElemDefinition(react.select, { 'name': 'pizza-toppings', 'multiple': true, diff --git a/test/unit/dom/matchers/has_value_test.dart b/test/unit/dom/matchers/has_value_test.dart index 0051290a..a62b3c89 100644 --- a/test/unit/dom/matchers/has_value_test.dart +++ b/test/unit/dom/matchers/has_value_test.dart @@ -30,10 +30,10 @@ void main() { void sharedHasValueTests(String description, {required Matcher Function([dynamic]) matcherFn, String valueDescription = 'value'}) { group(description, () { - late RenderResult view; - group('passes when the provided value matches the value found in a', () { group('TextInputElement', () { + late RenderResult view; + setUp(() { view = render(react.input({ 'type': 'text', @@ -57,6 +57,8 @@ void sharedHasValueTests(String description, }); group('TextAreaElement', () { + late RenderResult view; + setUp(() { view = render(react.textarea({ 'name': 'comment', @@ -74,6 +76,8 @@ void sharedHasValueTests(String description, }); group('NumberInputElement', () { + late RenderResult view; + setUp(() { view = render(react.input({ 'type': 'number', @@ -95,7 +99,7 @@ void sharedHasValueTests(String description, group('when only a single option can be selected', () { group('and a single option is selected', () { test('exact match', () { - view = render(react.select( + final view = render(react.select( { 'name': 'account-type', 'defaultValue': 'business', @@ -116,7 +120,7 @@ void sharedHasValueTests(String description, }); test('using a matcher', () { - view = render(react.select( + final view = render(react.select( {'name': 'account-type'}, react.option({ 'value': 'personal', @@ -145,7 +149,7 @@ void sharedHasValueTests(String description, }); test('and no option is selected', () { - view = render(react.select( + final view = render(react.select( {'name': 'account-type'}, react.option({ 'value': 'personal', @@ -163,6 +167,8 @@ void sharedHasValueTests(String description, group('when multiple options can be selected', () { group('and a single option is selected', () { + late RenderResult view; + setUp(() { view = render(react.select( { @@ -211,6 +217,8 @@ void sharedHasValueTests(String description, }); group('and multiple options are selected', () { + late RenderResult view; + setUp(() { view = render(react.select( { @@ -249,7 +257,7 @@ void sharedHasValueTests(String description, }); test('and no option is selected', () { - view = render(react.select( + final view = render(react.select( { 'name': 'pizza-toppings', 'multiple': true, @@ -281,7 +289,7 @@ void sharedHasValueTests(String description, group('the element is', () { test('a CheckboxInputElement', () { - view = render(react.input({ + final view = render(react.input({ 'type': 'checkbox', 'name': 'business-in-front', 'defaultChecked': true, @@ -295,7 +303,7 @@ void sharedHasValueTests(String description, }); test('an element with role="checkbox"', () { - view = render(react.div({ + final view = render(react.div({ 'role': 'checkbox', 'aria-checked': 'true', })); @@ -308,7 +316,7 @@ void sharedHasValueTests(String description, }); test('a RadioInputElement', () { - view = render(react.input({ + final view = render(react.input({ 'type': 'radio', 'name': 'business-in-front', 'defaultChecked': true, @@ -322,7 +330,7 @@ void sharedHasValueTests(String description, }); test('an element with role="radio"', () { - view = render(react.div({ + final view = render(react.div({ 'role': 'radio', 'aria-checked': 'true', })); @@ -337,7 +345,7 @@ void sharedHasValueTests(String description, group('the provided value does not match the value found in a', () { test('TextInputElement', () { - view = render(react.input({ + final view = render(react.input({ 'type': 'text', 'name': 'firstName', 'defaultValue': 'John', @@ -354,7 +362,7 @@ void sharedHasValueTests(String description, }); test('TextAreaElement', () { - view = render(react.textarea({ + final view = render(react.textarea({ 'name': 'comments', 'defaultValue': 'I have nothing nice to say', })); @@ -370,7 +378,7 @@ void sharedHasValueTests(String description, }); test('NumberInputElement', () { - view = render(react.input({ + final view = render(react.input({ 'type': 'number', 'name': 'age', 'defaultValue': 35, @@ -388,7 +396,7 @@ void sharedHasValueTests(String description, group('SelectElement', () { test('when only a single option can be selected', () { - view = render(react.select( + final view = render(react.select( { 'name': 'account-type', 'defaultValue': 'business', @@ -423,7 +431,7 @@ void sharedHasValueTests(String description, }); test('when multiple options can be selected', () { - view = render(react.select( + final view = render(react.select( { 'name': 'pizza-toppings', 'multiple': true, diff --git a/test/unit/dom/queries/by_testid_test.dart b/test/unit/dom/queries/by_testid_test.dart index 437680f1..26bf4a82 100644 --- a/test/unit/dom/queries/by_testid_test.dart +++ b/test/unit/dom/queries/by_testid_test.dart @@ -28,9 +28,9 @@ void main() { group('', () { initConfigForInternalTesting(); - late rtl.RenderResult view; - group('basic functionality', () { + late rtl.RenderResult view; + setUp(() { view = rtl.render(react.section( {}, @@ -275,6 +275,8 @@ void main() { group( 'the testId argument can target a matching testid when more than ' 'one testId is present on the data-test-id attribute', () { + late rtl.RenderResult view; + setUp(() { view = rtl.render(react.section( {}, diff --git a/test/unit/dom/queries/by_text_test.dart b/test/unit/dom/queries/by_text_test.dart index 3ab8abe2..06ba503b 100644 --- a/test/unit/dom/queries/by_text_test.dart +++ b/test/unit/dom/queries/by_text_test.dart @@ -27,11 +27,11 @@ void main() { group('', () { initConfigForInternalTesting(); - late rtl.RenderResult view; - group( 'the selector argument can be specified to target only matching ' 'element(s) when more than one has matching text:', () { + late rtl.RenderResult view; + setUp(() { view = rtl.render(react.div( {}, @@ -137,6 +137,8 @@ void main() { }); group('the ignore argument', () { + late rtl.RenderResult view; + setUp(() { view = rtl.render(react.div( {}, diff --git a/test/unit/dom/top_level_queries_test.dart b/test/unit/dom/top_level_queries_test.dart index 967d6b74..52d13953 100644 --- a/test/unit/dom/top_level_queries_test.dart +++ b/test/unit/dom/top_level_queries_test.dart @@ -81,8 +81,13 @@ void main() { group('contains queries that can be scoped to the specified container', () { const scopeName = 'top level'; - late Node container; - late String expectedPrettyDom; + Node? container; + String? expectedPrettyDom; + + tearDown(() { + container = null; + expectedPrettyDom = null; + }); Function _renderForQuery( Function query, { @@ -122,7 +127,7 @@ void main() { QueryType.AltText, textMatchArgName: TextMatchArgName.text, queryShouldMatchOn: scopeName, - getContainerForTopLevelQueries: () => container, + getContainerForTopLevelQueries: () => container!, topLevelQueryQueriesByName: { 'queryByAltText': ({renderMultipleElsMatchingQuery}) => _renderForQuery(rtl.queryByAltText, renderMultipleElsMatchingQuery: renderMultipleElsMatchingQuery), @@ -141,7 +146,7 @@ void main() { 'findAllByAltText': ({renderMultipleElsMatchingQuery}) => _renderForQuery(rtl.findAllByAltText, renderMultipleElsMatchingQuery: renderMultipleElsMatchingQuery, testAsyncQuery: true), }, - getExpectedPrettyDom: () => expectedPrettyDom, + getExpectedPrettyDom: () => expectedPrettyDom!, failureSnapshotPattern: 'alt text: $valueNotFoundPlaceholder', ); @@ -149,7 +154,7 @@ void main() { QueryType.DisplayValue, textMatchArgName: TextMatchArgName.value, queryShouldMatchOn: scopeName, - getContainerForTopLevelQueries: () => container, + getContainerForTopLevelQueries: () => container!, topLevelQueryQueriesByName: { 'queryByDisplayValue': ({renderMultipleElsMatchingQuery}) => _renderForQuery(rtl.queryByDisplayValue, renderMultipleElsMatchingQuery: renderMultipleElsMatchingQuery), @@ -168,7 +173,7 @@ void main() { 'findAllByDisplayValue': ({renderMultipleElsMatchingQuery}) => _renderForQuery(rtl.findAllByDisplayValue, renderMultipleElsMatchingQuery: renderMultipleElsMatchingQuery, testAsyncQuery: true), }, - getExpectedPrettyDom: () => expectedPrettyDom, + getExpectedPrettyDom: () => expectedPrettyDom!, failureSnapshotPattern: 'display value: $valueNotFoundPlaceholder', ); @@ -176,7 +181,7 @@ void main() { QueryType.LabelText, textMatchArgName: TextMatchArgName.text, queryShouldMatchOn: scopeName, - getContainerForTopLevelQueries: () => container, + getContainerForTopLevelQueries: () => container!, topLevelQueryQueriesByName: { 'queryByLabelText': ({renderMultipleElsMatchingQuery}) => _renderForQuery(rtl.queryByLabelText, renderMultipleElsMatchingQuery: renderMultipleElsMatchingQuery), @@ -195,7 +200,7 @@ void main() { 'findAllByLabelText': ({renderMultipleElsMatchingQuery}) => _renderForQuery(rtl.findAllByLabelText, renderMultipleElsMatchingQuery: renderMultipleElsMatchingQuery, testAsyncQuery: true), }, - getExpectedPrettyDom: () => expectedPrettyDom, + getExpectedPrettyDom: () => expectedPrettyDom!, failureSnapshotPattern: 'label with the text of: $valueNotFoundPlaceholder', ); @@ -203,7 +208,7 @@ void main() { QueryType.PlaceholderText, textMatchArgName: TextMatchArgName.text, queryShouldMatchOn: scopeName, - getContainerForTopLevelQueries: () => container, + getContainerForTopLevelQueries: () => container!, topLevelQueryQueriesByName: { 'queryByPlaceholderText': ({renderMultipleElsMatchingQuery}) => _renderForQuery(rtl.queryByPlaceholderText, renderMultipleElsMatchingQuery: renderMultipleElsMatchingQuery), @@ -225,7 +230,7 @@ void main() { renderMultipleElsMatchingQuery: renderMultipleElsMatchingQuery, testAsyncQuery: true), }, - getExpectedPrettyDom: () => expectedPrettyDom, + getExpectedPrettyDom: () => expectedPrettyDom!, failureSnapshotPattern: 'placeholder text of: $valueNotFoundPlaceholder', ); @@ -234,7 +239,7 @@ void main() { textMatchArgName: TextMatchArgName.role, textMatchArgSupportsFuzzyMatching: false, // exact = false is not supported by role queries queryShouldMatchOn: scopeName, - getContainerForTopLevelQueries: () => container, + getContainerForTopLevelQueries: () => container!, topLevelQueryQueriesByName: { 'queryByRole': ({renderMultipleElsMatchingQuery}) => _renderForQuery(rtl.queryByRole, renderMultipleElsMatchingQuery: renderMultipleElsMatchingQuery), @@ -253,7 +258,7 @@ void main() { 'findAllByRole': ({renderMultipleElsMatchingQuery}) => _renderForQuery(rtl.findAllByRole, renderMultipleElsMatchingQuery: renderMultipleElsMatchingQuery, testAsyncQuery: true), }, - getExpectedPrettyDom: () => expectedPrettyDom, + getExpectedPrettyDom: () => expectedPrettyDom!, failureSnapshotPattern: 'with the role "$valueNotFoundPlaceholder"', ); @@ -262,7 +267,7 @@ void main() { textMatchArgName: TextMatchArgName.name, textMatchArgSupportsFuzzyMatching: false, // exact = false is not supported by role queries queryShouldMatchOn: scopeName, - getContainerForTopLevelQueries: () => container, + getContainerForTopLevelQueries: () => container!, topLevelQueryQueriesByName: { 'queryByRole': ({renderMultipleElsMatchingQuery}) => _renderForQuery(rtl.queryByRole, renderMultipleElsMatchingQuery: renderMultipleElsMatchingQuery), @@ -281,7 +286,7 @@ void main() { 'findAllByRole': ({renderMultipleElsMatchingQuery}) => _renderForQuery(rtl.findAllByRole, renderMultipleElsMatchingQuery: renderMultipleElsMatchingQuery, testAsyncQuery: true), }, - getExpectedPrettyDom: () => expectedPrettyDom, + getExpectedPrettyDom: () => expectedPrettyDom!, failureSnapshotPattern: 'with the role "$validRoleInDom" and name "$valueNotFoundPlaceholder"', ); @@ -289,7 +294,7 @@ void main() { QueryType.TestId, textMatchArgName: TextMatchArgName.testId, queryShouldMatchOn: scopeName, - getContainerForTopLevelQueries: () => container, + getContainerForTopLevelQueries: () => container!, topLevelQueryQueriesByName: { 'queryByTestId': ({renderMultipleElsMatchingQuery}) => _renderForQuery(rtl.queryByTestId, renderMultipleElsMatchingQuery: renderMultipleElsMatchingQuery), @@ -308,7 +313,7 @@ void main() { 'findAllByTestId': ({renderMultipleElsMatchingQuery}) => _renderForQuery(rtl.findAllByTestId, renderMultipleElsMatchingQuery: renderMultipleElsMatchingQuery, testAsyncQuery: true), }, - getExpectedPrettyDom: () => expectedPrettyDom, + getExpectedPrettyDom: () => expectedPrettyDom!, failureSnapshotPattern: 'an element by: [data-test-id="$valueNotFoundPlaceholder"', ); @@ -316,7 +321,7 @@ void main() { QueryType.Text, textMatchArgName: TextMatchArgName.text, queryShouldMatchOn: '$scopeName single byText match', - getContainerForTopLevelQueries: () => container, + getContainerForTopLevelQueries: () => container!, topLevelQueryQueriesByName: { 'queryByText': ({renderMultipleElsMatchingQuery}) => _renderForQuery(rtl.queryByText, renderMultipleElsMatchingQuery: renderMultipleElsMatchingQuery), @@ -335,7 +340,7 @@ void main() { 'findAllByText': ({renderMultipleElsMatchingQuery}) => _renderForQuery(rtl.findAllByText, renderMultipleElsMatchingQuery: renderMultipleElsMatchingQuery, testAsyncQuery: true), }, - getExpectedPrettyDom: () => expectedPrettyDom, + getExpectedPrettyDom: () => expectedPrettyDom!, failureSnapshotPattern: 'an element with the text: $valueNotFoundPlaceholder', ); @@ -343,7 +348,7 @@ void main() { QueryType.Title, textMatchArgName: TextMatchArgName.title, queryShouldMatchOn: scopeName, - getContainerForTopLevelQueries: () => container, + getContainerForTopLevelQueries: () => container!, topLevelQueryQueriesByName: { 'queryByTitle': ({renderMultipleElsMatchingQuery}) => _renderForQuery(rtl.queryByTitle, renderMultipleElsMatchingQuery: renderMultipleElsMatchingQuery), @@ -362,7 +367,7 @@ void main() { 'findAllByTitle': ({renderMultipleElsMatchingQuery}) => _renderForQuery(rtl.findAllByTitle, renderMultipleElsMatchingQuery: renderMultipleElsMatchingQuery, testAsyncQuery: true), }, - getExpectedPrettyDom: () => expectedPrettyDom, + getExpectedPrettyDom: () => expectedPrettyDom!, failureSnapshotPattern: 'title: $valueNotFoundPlaceholder', ); }); diff --git a/test/unit/dom/wait_for_test.dart b/test/unit/dom/wait_for_test.dart index b0b6ae1b..db56005c 100644 --- a/test/unit/dom/wait_for_test.dart +++ b/test/unit/dom/wait_for_test.dart @@ -30,10 +30,10 @@ void main() { group('', () { initConfigForInternalTesting(); - late rtl.RenderResult view; - late Element rootElement; - group('waitFor()', () { + late rtl.RenderResult view; + late Element rootElement; + setUp(() { view = rtl.render(DelayedRenderOf({'childrenToRenderAfterDelay': elementsForQuerying('waitFor')})); rootElement = view.getByTestId('delayed-render-of-root'); @@ -193,6 +193,7 @@ void main() { late Node elementThatWontBeRemoved; final delayAfterWhichTheElementWillBeRemoved = asyncQueryTimeout ~/ 2; final shortTimeout = asyncQueryTimeout ~/ 4; + late rtl.RenderResult view; setUp(() { expect(shortTimeout, lessThan(delayAfterWhichTheElementWillBeRemoved), reason: 'test setup sanity check'); @@ -275,6 +276,7 @@ void main() { late Node anotherElementInDomButOutsideContainer; final delayAfterWhichTheElementWillBeRemoved = asyncQueryTimeout ~/ 2; final shortTimeout = asyncQueryTimeout ~/ 4; + late rtl.RenderResult view; setUp(() { expect(shortTimeout, lessThan(delayAfterWhichTheElementWillBeRemoved), reason: 'test setup sanity check'); diff --git a/test/unit/util/matchers.dart b/test/unit/util/matchers.dart index c5aa2306..4b7dcec4 100644 --- a/test/unit/util/matchers.dart +++ b/test/unit/util/matchers.dart @@ -37,9 +37,7 @@ Matcher toThrowErrorMatchingInlineSnapshot( ]) { final errorNameMatcher = hasToStringValue(contains('TestingLibraryElementError')); final snapshotMatcher = hasToStringValue(stringSnapshotMatcher); - final prettyDomMatcher = - // ignore: unnecessary_null_comparison - stringPrettyDomMatcher != null ? hasToStringValue(stringPrettyDomMatcher) : hasToStringValue(endsWith('')); + final prettyDomMatcher = hasToStringValue(stringPrettyDomMatcher); return throwsA(allOf(isA(), errorNameMatcher, snapshotMatcher, prettyDomMatcher, arbitraryMatcher1, arbitraryMatcher2, arbitraryMatcher3));