json_matcher 0.1.6 copy "json_matcher: ^0.1.6" to clipboard
json_matcher: ^0.1.6 copied to clipboard

discontinued
outdatedDart 1 only

JSON Matchers for unit tests: encodesToJson() checks if the value encodes to expected JSON, isJson() checks if the string is expected JSON.

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
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));
  });
}
2
likes
0
pub points
6%
popularity

Publisher

verified publisherkarapetov.com

JSON Matchers for unit tests: encodesToJson() checks if the value encodes to expected JSON, isJson() checks if the string is expected JSON.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

convert, matcher

More

Packages that depend on json_matcher