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...