我正在使用 freezed 从 json 制作对象:
@freezed
class UserMessagesResponseModel with _$UserMessagesResponseModel {
const factory UserMessagesResponseModel({
final Data? data,
}) = _UserMessagesResponseModel;
factory UserMessagesResponseModel.fromJson(final Map<String, dynamic> json) =>
_$UserMessagesResponseModelFromJson(json);
}
@freezed
class Data with _$Data {
const factory Data({
final Messages? messages,
}) = _Data;
factory Data.fromJson(final Map<String, dynamic> json) =>
_$DataFromJson(json);
}...
现在我正在尝试对创建的对象进行测试和检查类型:
test('should return a valid model', () async {
final jsonMap =
json.decode(fixture('message.json')) as Map<String, dynamic>;
final result = UserMessagesResponseModel.fromJson(
jsonMap,
);
expect(result, equals(UserMessagesResponseModel));
});
为什么我得到错误:
Expected: Type:<UserMessagesResponseModel>
Actual: _$_UserMessagesResponseModel:<UserMessagesResponseModel...
冷冻 不做相同的类型?如何检查类型?
我也用过:
expect(result, isA<UserMessagesResponseModel>);
但我得到了这个:
Expected: <Closure: () => TypeMatcher<UserMessagesResponseModel> from Function 'isA': static.>
Actual: _$_UserMessagesResponseModel:<UserMessagesResponseModel