Flutter test failure, unit test expected and actual state object are the same but still fail
625
you must override the == operator and hashCode or implement Equatable for that class.
To override them let's assume the class Person with the attributes name and age, it would look something like this:
class Person {
const Person(this.name, this.age);
final String name;
final int age
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Person &&
runtimeType == other.runtimeType &&
name == other.name &&
age == other.age;
@override
int get hashCode => name.hashCode ^ age.hashCode;
}
Author by
Rohmatul Laily
Updated on December 29, 2022Comments
-
Rohmatul Laily 10 months
I have a code test like this, the expected and the actual already have the same object, but the unit test still fails, what should I do?
blocTest("_mapClickEmailToState", wait: const Duration(milliseconds: 500), build: () { return bloc; }, act: (bloc) => bloc.add(ClickEmail()), expect: () => [ ClickEmailSuccess() ]); });
i have this error
Expected: [Instance of 'ClickEmailSuccess'] Actual: [Instance of 'ClickEmailSuccess'] Which: at location [0] is <Instance of 'ClickEmailSuccess'> instead of <Instance of 'ClickEmailSuccess'>
-
Jigar Patel over 2 yearsSeems like you need to override equality for
ClickEmailSuccess
class.
-
-
Rohmatul Laily over 2 yearsthank you, this is worked after implement Equatable for my class