Giter Club home page Giter Club logo

http-mock-adapter's Introduction

http-mock-adapter

Package Version Style: Lints Dart CI Publish Package LICENSE codecov

Description

http_mock_adapter is a simple to use mocking package for Dio intended to be used in tests. It provides various types and methods to declaratively mock request-response communication.

Usage

Here is a very basic usage scenario:

import 'package:dio/dio.dart';
import 'package:http_mock_adapter/http_mock_adapter.dart';

void main() async {
  final dio = Dio(BaseOptions());
  final dioAdapter = DioAdapter(dio: dio);

  const path = 'https://example.com';

  dioAdapter.onGet(
    path,
    (server) => server.reply(
      200,
      {'message': 'Success!'},
      // Reply would wait for one-sec before returning data.
      delay: const Duration(seconds: 1),
    ),
  );

  final response = await dio.get(path);

  print(response.data); // {message: Success!}
}

Real-world example

The intended usage domain is in tests when trying to simulate behavior of request-response communication with a server. The example portrays a decent use case of how one might make good use of the package.

Installing

Quick install

You can quickly install the package from the command-line:

With dart:

$ dart pub add --dev http_mock_adapter
...

With flutter:

$ flutter pub add --dev http_mock_adapter
...

Manual install

Depend on it

Add this to your package's pubspec.yaml file:

dev_dependencies:
  http_mock_adapter: ^0.4.2

Install it

You can then install the package from the command-line:

With dart:

$ dart pub get
...

With flutter:

$ flutter pub get
...

Alternatively, your editor might support dart pub get or flutter pub get. Check the docs for your editor to learn more.

Import it

Now in your Dart code, you can use:

import 'package:http_mock_adapter/http_mock_adapter.dart';

Changelog

All notable changes to this project will be documented in the CHANGELOG.md file.

Authors

See the AUTHORS file for information regarding the authors of the project.

License

http-mock-adapter is licensed under the permissive MIT License (LICENSE).

Contribution

For information regarding contributions, please refer to CONTRIBUTING.md file.

http-mock-adapter's People

Contributors

cyberail avatar giorgiberiashvili avatar kuhnroyal avatar lukagiorgadze avatar alexgorgadz3 avatar nataliehippe avatar theiskaa avatar ncb000gt avatar humblerookie avatar dricholm avatar eltehupkes avatar hannnes1 avatar jindrazak avatar sebastianklaiber avatar wangdengwu 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.