stefanhk31 / personal_blog_flutter

https://stefanhodgeskluck.com
2 stars 0 forks source link

Url Launcher test coverage #53

Open stefanhk31 opened 8 months ago

stefanhk31 commented 8 months ago

Might make sense to add a dedicated repository to wrap url launcher. It'd be light, but would solve the test cov issues and possibly also make some of the clickable link widgets cleaner?

...or better yet, can url launcher go in Blog repo?

stefanhk31 commented 7 months ago

Also possible to mock with MockPlatformInterfaceMixin:

class _MockUrlLauncherPlatform extends Mock
    with MockPlatformInterfaceMixin
    implements UrlLauncherPlatform {}

class _FakeLaunchOptions extends Fake implements LaunchOptions {}

// ... 
      late UrlLauncherPlatform urlLauncher;

      setUpAll(() async {
        registerFallbackValue(_FakeLaunchOptions());
      });

      setUp(() {
        urlLauncher = _MockUrlLauncherPlatform();

        UrlLauncherPlatform.instance = urlLauncher;

        when(() => urlLauncher.canLaunch(any())).thenAnswer((_) async => true);
        when(() => urlLauncher.launchUrl(any(), any()))
            .thenAnswer((_) async => true);
      });