felangel / mocktail

A mock library for Dart inspired by mockito
https://pub.dev/packages/mocktail
MIT License
617 stars 81 forks source link

[Suggestion] Change == override from Object to dynamic in Mock #87

Closed lulupointu closed 2 years ago

lulupointu commented 2 years ago

Is your feature request related to a problem? Please describe. When trying to mock certain object, their == override might use dynamic other instead of Object other, this will make mocking impossible because Mock.== uses Object.

An example of this is the Hive package, here is an example:

import 'package:hive/hive.dart';
import 'package:mocktail/mocktail.dart';

class MockBoxEvent extends Mock implements BoxEvent {}

The compiler will complain:

'Mock.==' ('bool Function(Object)') isn't a valid concrete implementation of 'BoxEvent.==' ('bool Function(dynamic)').

Describe the solution you'd like Change

class Mock {
...

  @override
  bool operator ==(Object other) {
    ...
  }
}

To:

class Mock {
...

  @override
  bool operator ==(dynamic other) {
    ...
  }
}

Describe alternatives you've considered Opening an issue into the other package, since Object is the right think to use. Which I did

Additional context Once again I know using Object is the right thing to do. However since Mock sub-classes will never be sub-classed using the widest possible element (dynamic) might be better. I would understand if you don't want to though, I just wanted to let you know this could be an issue for some.

Also thanks so much for this package and the other you created (read bloc). I've been using your packages since I started flutter and they helped me to learn a lot. So thank you !

felangel commented 2 years ago

Hi @lulupointu šŸ‘‹ Thanks for opening an issue and sorry for the delayed response!

I'd prefer to avoid making this change because, as you mentioned, Object is the preferred usage.

Closing for now but feel free to comment if you feel strongly about this change and I'm happy to continue the conversation, thanks! šŸ™