json_matcher 0.2.3

JSON Matchers for unit tests #

Provides:

  • encodesToJson() matcher which checks if the value encodes to expected JSON
  • isJson() matcher which checks if the string is expected JSON

See the example for more details.

Changelog #

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

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

0.2.3 - 2019-03-29

Changed #

  • Relaxed the required version of test

0.2.2 - 2018-08-13

Fixed #

  • Minor changelog fixes

0.2.1 - 2018-08-13

Fixed #

  • Minor linter issues

Added #

  • Usage example

0.2.0 - 2018-08-13

Changed #

  • Dart 2.0 compat

[0.1.6] - 2018-03-28

Fixed #

  • SCREAMING CAPS deprecation warning in dart:convert

[0.1.5] - 2018-03-19

Fixed #

  • Fixed minor linter issues in dart 2.0

0.1.4 - 2018-03-19

Fixed #

  • Fixed minor linter issues

0.1.3 - 2018-03-19

Added #

  • String matcher

0.1.2 - 2018-03-11

Added #

  • Analysis options

0.1.1 - 2018-03-11

Added #

  • Strong mode enabled

0.1.0 - 2018-03-10

Added #

  • encodesToJson() matcher

example/main.dart

import 'package:json_matcher/json_matcher.dart';
import 'package:test/test.dart';

class Foo {
  final String key;
  final String val;

  Foo(String this.key, String this.val);

  toJson() => {key: val}; // This object can be JSON-encoded
}

void main() {
  test('JSON encoding is performed', () {
    final foo = new Foo('hello', 'world');
    final json = {'hello': 'world'};
    expect(foo, encodesToJson(json)); // Ensuring foo encodes to proper JSON
  });

  test('Strings can be matched, key order does not matter', () {
    final string = '{"foo": "bar", "hello": "world"}';
    final json = {'hello': 'world', 'foo': 'bar'};
    expect(string, isJson(json));
  });
}

Use this package as a library

1. Depend on it

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


dependencies:
  json_matcher: ^0.2.3

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:json_matcher/json_matcher.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
14
Health:
Code health derived from static analysis. [more]
98
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
57
Learn more about scoring.

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

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:json_matcher/json_matcher.dart.

Health issues and suggestions

Document public APIs. (-1 points)

3 out of 3 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/src/processing_matcher.dart. (-1 points)

Analysis of lib/src/processing_matcher.dart reported 2 hints:

line 9 col 21: Don't type annotate initializing formals.

line 9 col 44: Don't type annotate initializing formals.

Format lib/src/json.dart.

Run dartfmt to format lib/src/json.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
convert ^2.0.0 2.1.1
matcher ^0.12.3 0.12.5
Transitive dependencies
charcode 1.1.2
path 1.6.4
stack_trace 1.9.3
typed_data 1.1.6
Dev dependencies
test ^1.3.0