Skip to content

HtmlDocument's visibilityState is String? when compiling tests. #93

Description

@harkairt

Please refer to this repository: https://github.com/harkairt/test_compile_error
especially this line

Steps:

  • clone the repository
  • fvm use (or simply use a global flutter 3.16.5)
  • flutter pub get && flutter run -d 'chrome'
    • works well, the app runs, and if you switch to a new tab, the proper message is written to debug console
  • flutter test
    • Error: Method 'toTabVisibilityChangeEvent' cannot be called on 'String?' because it is potentially null. Try calling using ?. instead.
    • if you switch out the commenting of these two lines
      final event = document.visibilityState.toTabVisibilityChangeEvent();
      // final event = (document.visibilityState ?? '').toTabVisibilityChangeEvent();
  • then executing the test again will succeed ✅

note: the IDE will warn about unnecessary fallback '' since it recognizes visibilityState to be String and not String?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions