mock_request 1.0.6

  • Readme
  • Changelog
  • Example
  • Installing
  • 65

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]
80
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
65
Learn more about scoring.

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

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, other

Primary library: package:mock_request/mock_request.dart with components: io.

Health suggestions

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

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

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.

line 31 col 3: Avoid return types on setters.

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

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

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.

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

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

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

line 24 col 23: Use = to separate a named parameter from its default value.

line 40 col 3: Avoid return types on setters.

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

line 73 col 9: DO use curly braces for all flow control structures.

line 75 col 9: DO use curly braces for all flow control structures.

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

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

line 43 col 23: Use = to separate a named parameter from its default value.

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

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

line 72 col 3: Avoid return types on setters.

line 85 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