Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fast Cached Network Image usage in Widget tests #53

Open
andrewpmoore opened this issue Apr 29, 2024 · 2 comments
Open

Fast Cached Network Image usage in Widget tests #53

andrewpmoore opened this issue Apr 29, 2024 · 2 comments
Labels
question Further information is requested

Comments

@andrewpmoore
Copy link

Hi
Thanks for the great package, really handy, there's just one issue I currently have which is that I run into issues when using widget tests that include using the library.

It'd be great is there was some 'init' option which just mocks the whole thing as at the moment the hive database causes the following error: No implementation found for method getApplicationDocumentsDirectory

@CHRISTOPANANJICKAL
Copy link
Owner

Can you please post a sample code that recreates this error?

@CHRISTOPANANJICKAL CHRISTOPANANJICKAL added the question Further information is requested label Apr 29, 2024
@andrewpmoore
Copy link
Author

Hi,
This is a cut down version of what I'm trying to do. Have a testWidget that I can run tests on

Here's the code

import 'package:fast_cached_network_image/fast_cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:path_provider/path_provider.dart';

void main() {
  testWidgets('Widget test', (WidgetTester tester) async {
    String storageLocation = (await getApplicationDocumentsDirectory()).path;
    await FastCachedImageConfig.init(subDir: storageLocation, clearCacheAfter: const Duration(days: 15));


    await tester.pumpWidget(const ProviderScope(child: MaterialApp(
      home: Scaffold(
        body: FastCachedImage(
          url: 'https://cdn.pixabay.com/photo/2024/04/01/05/18/green-8667981_1280.jpg',
          height: 250,
          fadeInDuration: Duration(milliseconds: 500),
          alignment: Alignment.center,
        ),
      ),
    )));

  });
}

The init has trouble because it's not on a platform and I think causes issues initializing hive.
Before using the package I could use https://pub.dev/packages/mocktail_image_network to mock images for tests (it instead of trying to load an image, just returns a transparent pixel), but with FastCachedNetworkImage it won't work without the .init call, but that doesn't work.

My thought was maybe there could be an init that's a mock that doesn't really do anything and then the FastCachedNetworkImage could do similar to the mocktail image network and not really make a network call and just return an empty image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants