platform/packages/json_god/test/to_json_test.dart

33 lines
700 B
Dart
Raw Normal View History

2021-03-07 15:56:09 +00:00
import 'package:json_god/json_god.dart' as god;
import 'package:test/test.dart';
import 'shared.dart';
main() {
god.logger.onRecord.listen(printRecord);
test('fromJson', () {
var foo = god.deserialize('{"bar":"baz"}', outputType: Foo) as Foo;
expect(foo is Foo, true);
expect(foo.text, equals('baz'));
});
test('toJson', () {
var foo = new Foo(text: 'baz');
var data = god.serializeObject(foo);
expect(data, equals({'bar': 'baz', 'foo': 'poobaz'}));
});
}
class Foo {
String text;
String get foo => 'poo$text';
Foo({this.text});
factory Foo.fromJson(Map json) => new Foo(text: json['bar'].toString());
Map toJson() => {'bar': text, 'foo': foo};
}