Tests for enum type conversion from mirror

This commit is contained in:
Tobe O 2018-08-03 18:42:35 -04:00
parent 79ffc00fb1
commit 01e3b067de
2 changed files with 5 additions and 0 deletions

View file

@ -24,6 +24,7 @@ class GraphQLEnumType<Value> extends GraphQLScalarType<Value, String>
@override @override
String serialize(Value value) { String serialize(Value value) {
if (value == null) return null;
return values.firstWhere((v) => v.value == value).name; return values.firstWhere((v) => v.value == value).name;
} }

View file

@ -28,6 +28,10 @@ void main() {
expect(asEnumType.serialize(RomanceLanguage.FRANCE), 'FRANCE'); expect(asEnumType.serialize(RomanceLanguage.FRANCE), 'FRANCE');
}); });
test('can serialize null', () {
expect(asEnumType.serialize(null), null);
});
test('fails to serialize invalid value', () { test('fails to serialize invalid value', () {
expect(() => asEnumType.serialize(34), throwsStateError); expect(() => asEnumType.serialize(34), throwsStateError);
}); });