json_matcher 0.2.2

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 52

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.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.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.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages 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';
  
Version Uploaded Documentation Archive
0.2.2 Aug 14, 2018 Go to the documentation of json_matcher 0.2.2 Download json_matcher 0.2.2 archive
0.2.1 Aug 14, 2018 Go to the documentation of json_matcher 0.2.1 Download json_matcher 0.2.1 archive
0.2.0 Aug 14, 2018 Go to the documentation of json_matcher 0.2.0 Download json_matcher 0.2.0 archive
0.1.7 Apr 1, 2018 Go to the documentation of json_matcher 0.1.7 Download json_matcher 0.1.7 archive
0.1.6 Mar 29, 2018 Go to the documentation of json_matcher 0.1.6 Download json_matcher 0.1.6 archive
0.1.5 Mar 19, 2018 Go to the documentation of json_matcher 0.1.5 Download json_matcher 0.1.5 archive
0.1.4 Mar 19, 2018 Go to the documentation of json_matcher 0.1.4 Download json_matcher 0.1.4 archive
0.1.3 Mar 19, 2018 Go to the documentation of json_matcher 0.1.3 Download json_matcher 0.1.3 archive
0.1.2 Mar 12, 2018 Go to the documentation of json_matcher 0.1.2 Download json_matcher 0.1.2 archive
0.1.1 Mar 12, 2018 Go to the documentation of json_matcher 0.1.1 Download json_matcher 0.1.1 archive

All 11 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
4
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
52
Learn more about scoring.

We analyzed this package on Sep 18, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.3

Platforms

Detected platforms: Flutter, web, other

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

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.54.0 <3.0.0
convert >=2.0.0 <3.0.0 2.0.2
matcher >=0.12.3 <0.12.4 0.12.3+1 0.12.4
Transitive dependencies
charcode 1.1.2
path 1.6.2
stack_trace 1.9.3
typed_data 1.1.6
Dev dependencies
test >=1.3.0 <1.4.0