dart-lang / mockito

Mockito-inspired mock library for Dart
https://pub.dev/packages/mockito
Apache License 2.0
623 stars 160 forks source link

Breaking change or typo? #744

Closed eernstg closed 2 months ago

eernstg commented 2 months ago

I don't know if there's anything deep in this, but I just noted that the following example from README.md in this section fails:

expect(cat.eatFood("fish"), isTrue); // Expected: true, actual <false>.

The test succeeds if this line is moved up such that it occurs before

when(cat.eatFood(any)).thenReturn(false);

Looks like that might just be working exactly as intended, but in that case the README.md file should probably be adjusted. Or perhaps I just misread the example?

yanok commented 2 months ago

Now I wonder how did you find it? :)

Documentation seems to be broken by https://github.com/dart-lang/mockito/commit/1dcd8225e9014b17ba256d7fa1d056f339189630, interestingly the executable version in example/example.dart doesn't have this line.

Out of set expectations the last matching one wins https://github.com/dart-lang/mockito/blob/3ef744f8749864f2a036eba60c4203cc8f638949/lib/src/mock.dart#L183, and it was like that since forever. I'll update the README to put that line above more specific expectation, thanks for reporting!

eernstg commented 2 months ago

Now I wonder how did you find it? :)

Just tried it. :grinning: