GithubHelp home page GithubHelp logo

j4qfrost / network_image_mock Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stelynx/network_image_mock

0.0 1.0 0.0 18 KB

Mock response for Image.network to help Flutter widget tests pass.

License: BSD 3-Clause "New" or "Revised" License

Dart 100.00%

network_image_mock's Introduction

Network Image Mock

Pub Version Lint & Test codecov.io

A utility for providing mocked response to Image.network in Flutter widget tests.

Introduction

Since you are here you probably already know that calling Image.network results in 400 response in Flutter widget tests. The reason for this is that default HTTP client in tests always return a 400.

So, what can we do about it? Instead of copying the whole code over and over again for mocking the HTTP client, I created this package. It is heavily inspired by roughike/image_test_utils, however that package is not being maintained despite multiple pull requests asking for bumping the mockito version and making the package usable again.

Installing

This package should be installed under dev_dependencies like

dev_dependencies:
  network_image_mock: ^1.1.0

Example

The package is quite straightforward to use. All you have to do is include it in your test file and wrap widget testing functions that require proper Image.network response in mockNetworkImagesFor() function provided by this package. A full test example could look like this.

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:network_image_mock/network_image_mock.dart';

Widget makeTestableWidget() => MaterialApp(home: Image.network(''));

void main() {
  testWidgets(
    'should properly mock Image.network and not crash',
    (WidgetTester tester) async {
      mockNetworkImagesFor(() => tester.pumpWidget(makeTestableWidget()));
    },
  );
}

This is actually an example taken from tests for this package.

Contributing

There is not much to contribute since the package serves its purpose, however, in chance of needing to bump or adjust some version, or any other suggestion for that matter, please read CONTRIBUTING.

network_image_mock's People

Contributors

andrzejchm avatar campovski avatar daohoangson avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.