Bloc: Bug or error in test caused by equatable

Created on 6 Apr 2019  Â·  1Comment  Â·  Source: felangel/bloc

Describe the bug
When I use this test class :

`import 'package:flutter_test/flutter_test.dart';
import 'package:meta/meta.dart';
import 'package:equatable/equatable.dart';
import 'package:bloc/bloc.dart';

abstract class LoginEvent extends Equatable {
LoginEvent([List props = const []]) : super(props);
}

class LoginButtonPressed extends LoginEvent {
@override
String toString() => 'LoginLoad';
}

abstract class LoginState extends Equatable {
LoginState([List props = const []]) : super(props);
}

class LoginStateLoading extends LoginState {
@override
String toString() => 'LoginStateLoading';
}

class LoginStateStart extends LoginState {
final num count;

LoginStateStart({@required this.count})
: super([count]);

@override
String toString() => 'LoginStateStart';
}

class LoginBloc extends Bloc {

LoginBloc();

@override
LoginState get initialState => LoginStateLoading();

@override
Stream mapEventToState(LoginEvent event) async* {
if (event is LoginButtonPressed) {
yield LoginStateStart(count: 10);
}
}
}

void main() {
LoginBloc loginBloc;

setUp(() {
loginBloc = LoginBloc();
});

test('initial state is correct', () {
expect(LoginStateLoading(), loginBloc.initialState);
});

test('emits token on success', () {
  final expectedResponse = [
    LoginStateLoading(),
    LoginStateStart(),
  ];

  expectLater(
    loginBloc.state,
    emitsInOrder(expectedResponse),
  );

  loginBloc.dispatch(LoginButtonPressed());
});

}`

I obtain
`
00:01 +1 -1: emits token on success [E]
Expected: should do the following in order:
• emit an event that LoginStateLoading:
• emit an event that LoginStateStart:
Actual: '>
Which: emitted • LoginStateLoading
• LoginStateStart
which didn't emit an event that LoginStateStart:

package:test_api expectLater
package:flutter_test/src/widget_tester.dart 199:10 expectLater
test/test.dart 66:7 main.
`

the error is caused by this line
yield LoginStateStart(count: 10);
if I use
yield LoginStateStart();
test works

OR if I use
`
class LoginStateStart extends LoginState {
final num count;

LoginStateStart({@required this.count})

@override
String toString() => 'LoginStateStart';
}
without super and withyield LoginStateStart(count: 10) ` , test work

Is it a bug or or am I missing something ?

I use

  • equatable: ^0.2.3
  • bloc: ^0.11.1

Most helpful comment

oupss I find My mistake.

>All comments

oupss I find My mistake.

Was this page helpful?
0 / 5 - 0 ratings