Unit testing 如何在颤振中测试密封状态类?
我在我的Flitter应用程序中使用冻结来生成密封的数据类。我需要测试它,我不知道怎么做。有什么想法吗?这是国家:Unit testing 如何在颤振中测试密封状态类?,unit-testing,flutter,bloc,freezed,Unit Testing,Flutter,Bloc,Freezed,我在我的Flitter应用程序中使用冻结来生成密封的数据类。我需要测试它,我不知道怎么做。有什么想法吗?这是国家: @freezed abstract class LoginState with _$LoginState { const factory LoginState({ @required Email email, @required Password password, @required bool isLoading, @required bool
@freezed
abstract class LoginState with _$LoginState {
const factory LoginState({
@required Email email,
@required Password password,
@required bool isLoading,
@required bool showErrors,
@required Option<Either<AuthFailure, Unit>> failureOrSuccessOption,
}) = _LoginState;
factory LoginState.initial() => LoginState(
failureOrSuccessOption: none(),
isLoading: false,
showErrors: false,
email: Email(''),
password: Password(''),
);
}
我想检查在执行cubit loginMethod时,它是否正确地将加载状态更改为true(在获得结果时),将加载状态更改为false(在获得结果后),但我收到以下错误消息:
Expected: should do the following in order:
* emit an event that _$_LoginState:<LoginState(email: Value(Left(EmailFailure.empty())), password: Value(Left(PasswordFailure.empty())), isLoading: true, showErrors: false, failureOrSuccessOption: None)>
* emit an event that _$_LoginState:<LoginState(email: Value(Left(EmailFailure.empty())), password: Value(Left(PasswordFailure.empty())), isLoading: false, showErrors: false, failureOrSuccessOption: None)>
Actual: _$_LoginState:<LoginState(email: Value(Left(EmailFailure.empty())), password: Value(Left(PasswordFailure.empty())), isLoading: false, showErrors: false, failureOrSuccessOption: None)>
Which: was not a Stream or a StreamQueue
Expected:应按顺序执行以下操作:
*发出一个$\u LoginState的事件:
*发出一个$\u LoginState的事件:
实际:$\u登录状态:
Which:不是流或流队列
Expected: should do the following in order:
* emit an event that _$_LoginState:<LoginState(email: Value(Left(EmailFailure.empty())), password: Value(Left(PasswordFailure.empty())), isLoading: true, showErrors: false, failureOrSuccessOption: None)>
* emit an event that _$_LoginState:<LoginState(email: Value(Left(EmailFailure.empty())), password: Value(Left(PasswordFailure.empty())), isLoading: false, showErrors: false, failureOrSuccessOption: None)>
Actual: _$_LoginState:<LoginState(email: Value(Left(EmailFailure.empty())), password: Value(Left(PasswordFailure.empty())), isLoading: false, showErrors: false, failureOrSuccessOption: None)>
Which: was not a Stream or a StreamQueue