isLeftOf function
Returns a matcher that matches if the actual object is of type Left
and
the underlying value is equal (for ==) to the expected value.
Example :
Either<Failure, String> either = fetchData();
expect((either as Left).value == 'foo', isTrue);
is equivalent to :
Either<Failure, String> either = fetchData();
expect(either, isLeftOf('foo'))
This matcher hasn't the same behavior than the equals
matcher when
comparing the two values :
test("isLefttOf work with == and not the 'equals' matcher", () {
var list1 = ['foo'];
var list2 = ['foo'];
// Unless list1 and list2 are declared with const in this example, list1 != list2
// This line passes the test
expect(list1 == list2, isFalse);
// But the `equals` matcher compares the two lists item by item.
// This line passes the test
expect(list1, equals(list2));
Either either = Left(list1);
//! Because list1 != list2, this line doesn't pass the test
expect(either, isLefttOf(list2));
// Use `isRightThat` instead
expect(either, isLefttThat(equals(list2)));
});
Implementation
Matcher isLeftOf(Object? expected) => _IsLeftOf(expected);