New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Equality for objects with a list parameter #46
Comments
Hi @HossamElharmeil 👋 I believe the issue is your |
I thought that might be the case too but it does extend equatable when I double checked :D
|
@HossamElharmeil what about |
I tried changing the props list only to contain the userID parameter but that did not work either which is really interesting. I think the issue is with the reservation class as you suggested but I'll have to figure out how
|
So, I implemented the exact same class without the DateTime parameter and this time it actually worked! I guess having a parameter that is not equatable by value in the class means the class itself cannot be equatable by value regardless of the parameters passed to props? Anyway, thank you so much for your help, Felix. At least I know how it works now xD
|
@HossamElharmeil yup you can create your own |
Somehow I got it to work by instantiating the list directly inside the test instead of declaring it in the main() function of the test and then passing it as a parameter.
Turns out that the implementation of |
Hi @felangel can we reopen this? Turns out i'm having the exact same problem as @HossamElharmeil. It may not be a problem with Equatable, but this behavior it's quite strange |
@rodrigobastosv can you provide a link to a sample which reproduces the issue? |
Sure, just let me get back at home and i'll provided it. Thanks |
Hi @felangel , this is my repo https://github.com/rodrigobastosv/firebase_bloc I created branchs with the problematic tests only
See that my model uses equatable with only id, so i expected to just work. There's another test that is oddly failing if you could please help telling me why. Thanks very much man! |
@rodrigobastosv will take a look shortly, thanks! |
@rodrigobastosv took a look and the problem is due to the fact that you're using an immutable list for import 'package:bloc_test/bloc_test.dart';
import 'package:firebase_bloc/model/congressman_model.dart';
import 'package:firebase_bloc/ui/bloc/bloc.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import '../mocks.dart';
void main() {
group('CongressBloc tests', () {
MockCongressRepository mockCongressRepository;
final List<CongressmanModel> congressPeople = [CongressmanModel(id: 1, nome: 'Test')];
setUp(() {
mockCongressRepository = MockCongressRepository();
});
blocTest(
'CongressFetch event results in [InitialCongressState, CongressLoadingState, CongressLoadedState]',
build: () {
when(mockCongressRepository.getCongressPeople())
.thenAnswer((_) => Future.value(congressPeople));
return CongressBloc((mockCongressRepository));
},
act: (bloc) {
bloc.add(CongressFetch());
return;
},
expect: [
InitialCongressState(),
CongressLoadingState(),
CongressLoadedState(congressPeople)
],
);
blocTest(
'CongressFetch event results in [InitialCongressState, CongressLoadingState, CongressLoadedFailledState] when error happens',
build: () {
when(mockCongressRepository.getCongressPeople())
.thenThrow(Exception('Opsie Dasie'));
return CongressBloc((mockCongressRepository));
},
act: (bloc) {
bloc.add(CongressFetch());
return;
},
expect: [
InitialCongressState(),
CongressLoadingState(),
CongressLoadedFailledState('Exception: Opsie Dasie')
],
);
});
} Also (tests still pass without this) but I noticed that you're not passing all props in @override
List<Object> get props => [id]; Hope that helps 👍 |
Thanks for the reply @felangel ! |
I'm playing around with the new library bloc_test for flutter and I implemented the following test
This is the implementation of ReservationsLoadSuccess
Where ReservationState extends Equatable Now, when running the test, you get the following error
Basically saying that the state ReservationsLoadSuccess at position 2 in the actual list is not equal to its peer in the expected list.
I tried overriding the == operator in the ReservationsLoadSuccess class as follows
But that didn't seem to work and running the test still outputted the same error. The only way I got it to work is to leave the props method returning an empty list or adding any other dummy variable and pass it to the props list.
Is there any way I can make the class equatable in regards to the list parameter?
The text was updated successfully, but these errors were encountered: