Dart is checking for referential equality as default, and here you are compoaring two arrays which have equal values but not equal reference. Constant lists will behave as you expected, while runtime defined lists will not.
final a = ['Two', 'Three'] == ['Two', 'Three']; // false
final b = const ['Two', 'Three'] == const ['Two', 'Three']; // true
It can be confusing since this will pass:
expect(['Two', 'Three'], equals(['Two', 'Three']));
The testing libary has default matchers of iterators and will do a deep check to match all the strings in the list, therefore the above passes. That is not the case for the Right
data type, which will fallback to the ==
-operator and therefore fails, since it will return false as shown above.
Dartz has a list implementation (immutable) that checks for deep equality which will succeed, or with const as described above:
final a2 = ilist('Two', 'Three') == ilist('Two', 'Three') // true
expect(Right(ilist(['Two', 'Three'])), equals(Right(ilist(['Two', 'Three']))));
expect(Right(const ['Two', 'Three']), equals(Right(const ['Two', 'Three'])));