mock_request 1.0.6

  • Readme
  • Changelog
  • Example
  • Installing
  • 62

mock_request #

Pub build status

Manufacture dart:io HttpRequests, HttpResponses, HttpHeaders, etc. This makes it possible to test server-side Dart applications without having to ever bind to a port.

This package was originally designed to testing Angel applications smoother, but works with any Dart-based server. :)

Usage #

var rq = new MockHttpRequest('GET', Uri.parse('/foo'));
await rq.close();
await app.handleRequest(rq); // Run within your server-side application
var rs = rq.response;
expect(rs.statusCode, equals(200));
expect(await rs.transform(UTF8.decoder).join(),
    equals(JSON.encode('Hello, world!')));

More examples can be found in the included tests.

1.0.6 #

  • Prepare for upcoming Dart SDK change whereby HttpRequest implements Stream<Uint8List> rather than Stream<List<int>>.

1.0.5 #

  • Add toString to MockHttpHeaders.

1.0.4 #

  • Fix for ifModifiedSince

1.0.3 #

  • Dart2 fixes
  • Apparently fix hangs that break Angel tests

example/main.dart

import 'package:mock_request/mock_request.dart';

main() async {
  var rq = new MockHttpRequest('GET', Uri.parse('/foo'));
  await rq.close();
}

Use this package as a library

1. Depend on it

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


dependencies:
  mock_request: ^1.0.6

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:mock_request/mock_request.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
42
Health:
Code health derived from static analysis. [more]
71
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
62
Learn more about scoring.

We analyzed this package on Dec 10, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.1+4

Health suggestions

Fix lib/src/request.dart. (-9.54 points)

Analysis of lib/src/request.dart reported 20 hints, including:

line 13 col 27: Unnecessary new keyword.

line 14 col 44: Unnecessary new keyword.

line 17 col 47: Unnecessary new keyword.

line 24 col 7: Unnecessary new keyword.

line 27 col 31: Unnecessary new keyword.

Fix lib/src/response.dart. (-9.54 points)

Analysis of lib/src/response.dart reported 20 hints, including:

line 9 col 23: Unnecessary new keyword.

line 11 col 27: Unnecessary new keyword.

line 12 col 44: Unnecessary new keyword.

line 13 col 47: Unnecessary new keyword.

line 20 col 7: Unnecessary new keyword.

Fix lib/src/headers.dart. (-7.24 points)

Analysis of lib/src/headers.dart reported 15 hints, including:

line 8 col 33: Unnecessary new keyword.

line 12 col 7: DO use curly braces for all flow control structures.

line 14 col 7: DO use curly braces for all flow control structures.

line 17 col 3: Avoid return types on setters.

line 24 col 3: Avoid return types on setters.

Fix lib/src/lockable_headers.dart. (-6.31 points)

Analysis of lib/src/lockable_headers.dart reported 13 hints, including:

line 7 col 31: Unnecessary new keyword.

line 17 col 7: DO use curly braces for all flow control structures.

line 19 col 7: DO use curly braces for all flow control structures.

line 25 col 7: DO use curly braces for all flow control structures.

line 27 col 7: DO use curly braces for all flow control structures.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <3.0.0
charcode >=1.0.0 <2.0.0 1.1.2
Dev dependencies
angel_framework ^2.0.0-alpha
http ^0.11.0
test ^1.0.0