isRightOf function

Matcher isRightOf(
  1. Object? expected
)

Returns a matcher that matches if the actual object is of type Right and the underlying value is equal (for ==) to the expected value.

Example :

Either<Failure, String> either = fetchData();

expect((either as Right).value == 'foo', isTrue);

is equivalent to :

Either<Failure, String> either = fetchData();

expect(either, isRightOf('foo'))

This matcher hasn't the same behavior than the equals matcher when comparing the two values :

test("isRightOf 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 = Right(list1);

   //! Because list1 != list2, this line doesn't pass the test
   expect(either, isRightOf(list2));

   // Use `isRightThat` instead
   expect(either, isRightThat(equals(list2)));

 });

Implementation

Matcher isRightOf(Object? expected) => _IsRightOf(expected);