为什么我从bloctest函数中获取空的实际数组?
因此,我正在为我的项目实施bloctesting,并且从特定功能中获得一个空的实际阵列。
share_bloc_test.dart 以下是返回空的实际数组的blocfunction的代码。
group('ShareDisconnectGrantor', () {
blocTest<ShareBloc, ShareState>(
'emits [ShareLoadSuccess] '
'state when successfully disconnected grantor',
seed: () => ShareLoadSuccess(ConnectedUsersModel(List<ConnectedUserModel>.filled(1, ConnectedUserModel(1234, '1234', '1234')), List<ConnectedUserModel>.filled(1, ConnectedUserModel(1234, '1234', '1234'))), connectModel: ConnectModel('1234', dateTime, dateTime, dateTime, '1234', '1234')),
setUp: () {
when(
shareRepositoryMock.disconnectFromGrantor(1234, 1234),
).thenAnswer(
(_) => Future<ConnectedUsersModel>.value(ConnectedUsersModel(List<ConnectedUserModel>.filled(1, ConnectedUserModel(1234, '1234', '1234')), List<ConnectedUserModel>.filled(1, ConnectedUserModel(1234, '1234', '1234')))),
);
},
build: () => ShareBloc(
authenticationBloc: AuthenticationBloc(
authenticationRepository: authenticationRepositoryMock),
shareRepository: shareRepositoryMock),
act: (ShareBloc bloc) => bloc.add(
const ShareDisconnectGrantor(1234, 1234),
),
expect: () => [
ShareLoadSuccess(ConnectedUsersModel(List<ConnectedUserModel>.filled(1, ConnectedUserModel(1234, '1234', '1234')), List<ConnectedUserModel>.filled(1, ConnectedUserModel(1234, '1234', '1234'))), connectModel: ConnectModel('1234', dateTime, dateTime, dateTime, '1234', '1234')),
],
);
});
share_bloc.dart 以下是与事件相对应的函数的代码
Future<void> _onDisconnectGrantor(
ShareDisconnectGrantor event, Emitter<ShareState> emit) async {
if (state is ShareLoadSuccess) {
final ShareLoadSuccess _currentState = state as ShareLoadSuccess;
final ConnectedUsersModel _shareUsers = await shareRepository
.disconnectFromGrantor(event.userId, event.grantorId);
return emit(_currentState.copyWith(shareUsers: _shareUsers));
}
}
。 以下是上述bloctest函数的状态代码,
part of 'share_bloc.dart';
abstract class ShareState extends Equatable {
const ShareState();
@override
List<Object?> get props => <Object?>[];
}
class ShareInitial extends ShareState {}
class ShareGranteeSuccess extends ShareState {}
class ShareGranteeFailure extends ShareState {
final KBMException exception;
const ShareGranteeFailure({required this.exception});
@override
List<Object?> get props => <Object?>[exception];
}
class ShareGrantorSuccess extends ShareState {}
class ShareGrantorFailure extends ShareState {
final KBMException exception;
const ShareGrantorFailure({required this.exception});
@override
List<Object?> get props => <Object?>[exception];
}
class ShareConnectSuccess extends ShareState {}
class ShareConnectFailure extends ShareState {
final KBMException exception;
const ShareConnectFailure({required this.exception});
@override
List<Object?> get props => <Object?>[exception];
}
class ShareLoadSuccess extends ShareState {
final ConnectedUsersModel shareUsers;
final ConnectModel? connectModel;
final bool isGrantor;
const ShareLoadSuccess(this.shareUsers, {this.connectModel, this.isGrantor = false});
@override
List<Object?> get props => <Object?>[shareUsers, connectModel, isGrantor];
ShareLoadSuccess copyWith({
ConnectedUsersModel? shareUsers,
ConnectModel? connectModel,
bool? isGrantor,
}) {
return ShareLoadSuccess(
shareUsers ?? this.shareUsers,
connectModel: connectModel ?? this.connectModel,
isGrantor: isGrantor ?? this.isGrantor,
);
}
}
class ShareGrantorAborted extends ShareState {}
class ShareSyncInProgress extends ShareState {
final ConnectModel? connectModel;
const ShareSyncInProgress({this.connectModel});
@override
List<Object?> get props => <Object?>[connectModel];
}
我有点没有想法。如果有人知道会发生什么,请帮助...
So I'm implementing blocTesting for my project and I'm getting an empty actual array from a specific feature.
share_bloc_test.dart
Below is the code for the blocFunction that is returning the empty actual array.
group('ShareDisconnectGrantor', () {
blocTest<ShareBloc, ShareState>(
'emits [ShareLoadSuccess] '
'state when successfully disconnected grantor',
seed: () => ShareLoadSuccess(ConnectedUsersModel(List<ConnectedUserModel>.filled(1, ConnectedUserModel(1234, '1234', '1234')), List<ConnectedUserModel>.filled(1, ConnectedUserModel(1234, '1234', '1234'))), connectModel: ConnectModel('1234', dateTime, dateTime, dateTime, '1234', '1234')),
setUp: () {
when(
shareRepositoryMock.disconnectFromGrantor(1234, 1234),
).thenAnswer(
(_) => Future<ConnectedUsersModel>.value(ConnectedUsersModel(List<ConnectedUserModel>.filled(1, ConnectedUserModel(1234, '1234', '1234')), List<ConnectedUserModel>.filled(1, ConnectedUserModel(1234, '1234', '1234')))),
);
},
build: () => ShareBloc(
authenticationBloc: AuthenticationBloc(
authenticationRepository: authenticationRepositoryMock),
shareRepository: shareRepositoryMock),
act: (ShareBloc bloc) => bloc.add(
const ShareDisconnectGrantor(1234, 1234),
),
expect: () => [
ShareLoadSuccess(ConnectedUsersModel(List<ConnectedUserModel>.filled(1, ConnectedUserModel(1234, '1234', '1234')), List<ConnectedUserModel>.filled(1, ConnectedUserModel(1234, '1234', '1234'))), connectModel: ConnectModel('1234', dateTime, dateTime, dateTime, '1234', '1234')),
],
);
});
share_bloc.dart
Below is the code for the function corresponding to the event the above code is associated with
Future<void> _onDisconnectGrantor(
ShareDisconnectGrantor event, Emitter<ShareState> emit) async {
if (state is ShareLoadSuccess) {
final ShareLoadSuccess _currentState = state as ShareLoadSuccess;
final ConnectedUsersModel _shareUsers = await shareRepository
.disconnectFromGrantor(event.userId, event.grantorId);
return emit(_currentState.copyWith(shareUsers: _shareUsers));
}
}
share_state.dart
Below is the code for state for the above bloctest function
part of 'share_bloc.dart';
abstract class ShareState extends Equatable {
const ShareState();
@override
List<Object?> get props => <Object?>[];
}
class ShareInitial extends ShareState {}
class ShareGranteeSuccess extends ShareState {}
class ShareGranteeFailure extends ShareState {
final KBMException exception;
const ShareGranteeFailure({required this.exception});
@override
List<Object?> get props => <Object?>[exception];
}
class ShareGrantorSuccess extends ShareState {}
class ShareGrantorFailure extends ShareState {
final KBMException exception;
const ShareGrantorFailure({required this.exception});
@override
List<Object?> get props => <Object?>[exception];
}
class ShareConnectSuccess extends ShareState {}
class ShareConnectFailure extends ShareState {
final KBMException exception;
const ShareConnectFailure({required this.exception});
@override
List<Object?> get props => <Object?>[exception];
}
class ShareLoadSuccess extends ShareState {
final ConnectedUsersModel shareUsers;
final ConnectModel? connectModel;
final bool isGrantor;
const ShareLoadSuccess(this.shareUsers, {this.connectModel, this.isGrantor = false});
@override
List<Object?> get props => <Object?>[shareUsers, connectModel, isGrantor];
ShareLoadSuccess copyWith({
ConnectedUsersModel? shareUsers,
ConnectModel? connectModel,
bool? isGrantor,
}) {
return ShareLoadSuccess(
shareUsers ?? this.shareUsers,
connectModel: connectModel ?? this.connectModel,
isGrantor: isGrantor ?? this.isGrantor,
);
}
}
class ShareGrantorAborted extends ShareState {}
class ShareSyncInProgress extends ShareState {
final ConnectModel? connectModel;
const ShareSyncInProgress({this.connectModel});
@override
List<Object?> get props => <Object?>[connectModel];
}
I kinda have no ideas what might be the issue here. If anyone knows what might be happening please help...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论