mockery 0.0.1 copy "mockery: ^0.0.1" to clipboard
mockery: ^0.0.1 copied to clipboard

outdated

Simple mock recipes for making Flutter testing easier.

mockery #

A simple Dart package containing recipes for mocking objects in Dart and Flutter

Mocking HTTP Image Calls #

The first (and currently only) recipe here mocks a http call destined to retrieve an image and returns a one pixel image without touching the network. This is great for testing Flutter widgets that hit the network with things like Image.network.

Wrap the code making the http call with HttpOverrides.runZoned and pass in a reference to createMockImageHttpClient.

import 'dart:io';

import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockery/mock_http_image.dart';

void main() {
  testWidgets('images are successfully mocked in http', (tester) async {
    HttpOverrides.runZoned(() async {
      await tester.pumpWidget(
          // The url doesn't matter, anything will do
          Image.network('https://www.example.com/images/image.png'));
    }, createHttpClient: createMockImageHttpClient);
  });
}
0
likes
20
pub points
0%
popularity

Publisher

unverified uploader

Simple mock recipes for making Flutter testing easier.

Repository (GitHub)
View/report issues

License

BSD-3-Clause (LICENSE)

Dependencies

mockito

More

Packages that depend on mockery