Bloc: Failing test cases

Created on 24 Jun 2019  路  2Comments  路  Source: felangel/bloc

Hi @felangel

I am not able to figure it out what below error wants to say

========================================================
package:test_api expectLater
package:flutter_test/src/widget_tester.dart 233:10 expectLater
testcomcureambit\mobile\bloc\otp\otp_bloc_test.dart 18:5 main.

Expected:
Actual:

==========================================================

Even though both expected and actual are similar then too this is failing.

can you please help me to figure it out why is it failing????

bloc code

```import 'dart:async';

import 'package:bloc/bloc.dart';
import 'package:root/com/cureambit/mobile/service/otp_service.dart';

import './bloc.dart';

class OTPBloc extends Bloc {
final OTPRepository _otpRepository;

OTPBloc(this._otpRepository);

@override
OtpBlocState get initialState => OTPTimerInitialise();

@override
Stream mapEventToState(
OtpBlocEvent event,
) async* {
if (event is TimerCompleted) {
yield OTPResendInitialise();
}
if (event is ResendOTP) {
yield OTPTimerInitialise();
await Future.delayed(Duration(seconds: 2));
}
if (event is OTPSubmission) {
bool isValidOtp = await _otpRepository.validateOTP(event.otpValue);
if (!isValidOtp) {
yield OTPFailure();
} else {
yield OTPSuccess();
}
}
}
}


**test code**

import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:root/com/cureambit/mobile/bloc/otp/bloc.dart';
import 'package:root/com/cureambit/mobile/service/otp_service.dart';

class OTPRepositoryMock extends Mock implements OTPRepository {}

void main() {
OTPRepositoryMock _otpRepository;
OTPBloc _otpBloc;

setUp(() {
_otpRepository = OTPRepositoryMock();
_otpBloc = OTPBloc(_otpRepository);
});

test("Initial state should be 'OTPTimerInitialise'", () {
expectLater(
_otpBloc.initialState,
OTPTimerInitialise(),
);
});

test('dispose does not emit new states', () {
expectLater(
_otpBloc.state, emitsInOrder([OTPTimerInitialise(), emitsDone]));
_otpBloc.dispose();
});
}
```

both the test cases are failing.

question

Most helpful comment

Hi @felangel

Thank you this got resolved :)

All 2 comments

Hi @JONA-Cureambit 馃憢
Thanks for opening an issue!

Is your OtpBlocState extending Equatable or overriding == and hashCode? If not then you need to make that change in order to assert that two different instances of the object are equal.

Let me know if that helps 馃憤

Hi @felangel

Thank you this got resolved :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MahdiPishguy picture MahdiPishguy  路  3Comments

craiglabenz picture craiglabenz  路  3Comments

Reidond picture Reidond  路  3Comments

shawnchan2014 picture shawnchan2014  路  3Comments

rsnider19 picture rsnider19  路  3Comments