Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flutter_test expect throws error on Right with List #45

Closed
adamsmaka opened this issue May 15, 2020 · 5 comments
Closed

flutter_test expect throws error on Right with List #45

adamsmaka opened this issue May 15, 2020 · 5 comments

Comments

@adamsmaka
Copy link

Hi, I cannot test dartz Right value when type is a list.

  Either<dynamic, List<String>> getStrings() {
    return Right(['Two', 'Three']);
  }
      test(
        'STRINGS',
        () {
          final result = repository.getStrings();
          expect(result, equals(Right(['Two', 'Three'])));
        },
      );

The code above throws error:

ERROR: Expected: Right<dynamic, List>:<Right([Two, Three])>
Actual: Right<dynamic, List>:<Right([Two, Three])>

What am I doing wrong?

@adamsmaka
Copy link
Author

Even code like this doesn't work :(
expect(Right(['Two', 'Three']), equals(Right(['Two', 'Three'])));

@mateusfccp
Copy link

mateusfccp commented May 15, 2020

@adamsmaka Your problem probably has nothing to do with dartz. The same would happen if you was simply comparing the two inner lists, because this is how Dart works regarding lists comparison: it will compare the hashcodes, instead of the list items.

Have a look at #39, the issue is the same.

@spebbe
Copy link
Owner

spebbe commented May 15, 2020

As @mateusfccp writes, this is expected behaviour of List equality. If you are able/willing to use IList instead of List, it provides more intuitive default equality semantics, e.g expect(Right(ilist(['Two', 'Three'])), equals(Right(ilist(['Two', 'Three'])))); will succeed.

@adamsmaka
Copy link
Author

adamsmaka commented May 15, 2020

I did something like that and it works 🤔

if (result.isRight()) {
  final resultList = result.getOrElse(null);
  expect(resultList, equals(myList));
}
expect(result.isRight(), true);

Anyway thanks for answers!

@spebbe
Copy link
Owner

spebbe commented May 15, 2020

Yes, the test framework includes special treatment for naked List instances. OK to close?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants