Comments (14)
Thanks for the reply @felangel !
from equatable.
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
class ReservationTest extends Equatable {
final String salon;
final String userID;
ReservationTest({this.salon, this.userID});
Map<String, dynamic> toJson() {
return {
'userID': userID,
'salon': salon,
};
}
@override
String toString() {
return "Reservation => userID: $userID, salon: $salon";
}
@override
List<Object> get props => [salon, userID];
}
from equatable.
@HossamElharmeil yup you can create your own EquatableDateTime
by using the EquatableMixin
. Closing for now but feel free to comment with additional questions/comments and I'm happy to continue the conversation 👍
from equatable.
Hi @felangel can we reopen this? Turns out i'm having the exact same problem as @HossamElharmeil.
When i instantiate the list directly on the test it works, if i initialize the list inside setUp it doesn't work.
It may not be a problem with Equatable, but this behavior it's quite strange
from equatable.
Hi @felangel , this is my repo https://github.com/rodrigobastosv/firebase_bloc
I created branchs with the problematic tests only
- The branch passing-tests has the tests working with some workarounds
- The branch failling-tests has the tests as i expected to be, but that are failing to pass
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!
from equatable.
Hi @HossamElharmeil 👋
Thanks for opening an issue!
I believe the issue is your Reservation
class is not extending Equatable
. Can you please confirm? Thanks!
from equatable.
I thought that might be the case too but it does extend equatable when I double checked :D
Here is the implementation
class Reservation extends Equatable {
final String salon;
final String userID;
final DateTime dateTime;
Reservation({this.salon, this.userID, this.dateTime});
@override
String toString() {
return "Reservation => userID: $userID, salon: $salon, date: $dateTime";
}
Map<String, dynamic> toJson() {
return {
'userID': userID,
'salon': salon,
'dateTime': dateTime,
};
}
@override
List<Object> get props => [salon, userID, dateTime];
}
from equatable.
@HossamElharmeil what about DateTime
? I think that might be the problem.
from equatable.
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
class Reservation extends Equatable {
final String salon;
final String userID;
final DateTime dateTime;
Reservation({this.salon, this.userID, this.dateTime});
@override
String toString() {
return "Reservation => userID: $userID, salon: $salon, date: $dateTime";
}
Map<String, dynamic> toJson() {
return {
'userID': userID,
'salon': salon,
'dateTime': dateTime,
};
}
@override
List<Object> get props => [userID];
}
from equatable.
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.
blocTest('should return ReservationsLoadSucess when the use case returns a list of reservationsList',
build: () {
when(mockGetReservations(any)).thenAnswer((_) async => Right([Reservation(user: "12345", salon: "salon", dateTime: DateTime(1998, 8,8))]));
return ReservationBloc(getReservations: mockGetReservations);
},
act: (bloc) async {
bloc.add(ReservationsRequested(user));
},
expect: [
ReservationsInitial(),
ReservationsLoadInProgress(),
ReservationsLoadSuccess([Reservation(user: "12345", salon: "salon", dateTime: DateTime(1998, 8,8))]),
],
);
Turns out that the implementation of DateTime
does actually override the equals operator for value equality, it had to do with the declaration of the list which is kinda weird. Maybe I'll have to do some research about runtime and compile time stuff in dart when it comes to initializing something in a list.
from equatable.
@rodrigobastosv can you provide a link to a sample which reproduces the issue?
from equatable.
Sure, just let me get back at home and i'll provided it. Thanks
from equatable.
@rodrigobastosv will take a look shortly, thanks!
from equatable.
@rodrigobastosv took a look and the problem is due to the fact that you're using an immutable list for congressPeople
.
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 CongressmanModel
@override
List<Object> get props => [id];
Hope that helps 👍
from equatable.
Related Issues (20)
- Same hashcode for different new lists HOT 1
- Equality and Hashcode differ for Sets with different order
- Equatable doesn't checks for Equality for variables in parent class HOT 3
- feat request: add `stringifyProps` HOT 4
- Enum implementing Equatable related classes HOT 3
- Same object, same runtimeType but runtimeType== other.runtimeType is false HOT 3
- Storing the hashCode HOT 3
- Doesn't work with List<File> as property HOT 1
- `runtimeType` prevents from using generic type HOT 5
- Provide lint for forgotten fields in props HOT 3
- List of object dosen't work correctly HOT 12
- `Equatable` is redundant with `EquatableMixin` HOT 1
- Upgrade sdk to include Dart 3 HOT 3
- A Map considered equal even if its not HOT 3
- Why do we need to compare runtimeType? HOT 5
- Support for mutable class objects HOT 3
- `Foo(1) == Foo(1.0)` is false HOT 2
- Do Equatable actually need to be immutable HOT 1
- Publish a new version HOT 2
- Is that logical? Object equals but element not equals. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from equatable.