You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think I've noticed an issue with the @GenerateMocks annotation when it comes to applying secondary generic types (i.e. types of a type). For example the following class/mocks:
// Mocks generated by Mockito 5.0.7 from annotations// in project/test/test_mock.dart.// Do not manually edit this file.import'package:mockito/mockito.dart'as _i1;
import'test_mock.dart'as _i2;
// ignore_for_file: comment_references// ignore_for_file: unnecessary_parenthesis// ignore_for_file: prefer_const_constructors// ignore_for_file: avoid_redundant_argument_values/// A class which mocks [Foo].////// See the documentation for Mockito's code generation for more information.classMockFooextends _i1.Mockimplements _i2.Foo<Map> {
MockFoo() {
_i1.throwOnMissingStub(this);
}
@overridevoiddoNothing(Map<String, dynamic>? arg) =>super.noSuchMethod(Invocation.method(#doNothing, [arg]),
returnValueForMissingStub:null);
}
This produces a compilation error on the MockFoo override of doNothing that states: 'MockFoo.doNothing' ('void Function(Map<String, dynamic>?)') isn't a valid override of 'Foo.doNothing' ('void Function(Map<dynamic, dynamic>)').dartinvalid_override
As far as I can tell, this is because when the MockFoo class is implementing Foo it is erasing the type parameters of the Map<String, dynamic> to just Map. If I manually change Foo<Map> to Foo<Map<String, dynamic>> it fixes the issue. I ran into this whilst mocking elements of the FlutterFire Firestore package which (in its current version) uses Map<String, dynamic> as a default type, so I can imagine it may cause problems for others too.
I did have a look over the documentation/issues and couldn't see anything open to cover this, but I won't be too surprised if I've just tried using something incorrectly.
Thanks!
The text was updated successfully, but these errors were encountered:
Good catch; on the surface this definitely looks like a bug, but I'm surprised we don't have tests for this...
srawlins
added
P2
A bug or feature request we're likely to work on
type-bug
Incorrect behavior (everything from a crash to more subtle misbehavior)
labels
May 17, 2021
Hi there,
I think I've noticed an issue with the
@GenerateMocks
annotation when it comes to applying secondary generic types (i.e. types of a type). For example the following class/mocks:Produces this as generated mock code:
This produces a compilation error on the
MockFoo
override ofdoNothing
that states:'MockFoo.doNothing' ('void Function(Map<String, dynamic>?)') isn't a valid override of 'Foo.doNothing' ('void Function(Map<dynamic, dynamic>)').dartinvalid_override
As far as I can tell, this is because when the
MockFoo
class is implementingFoo
it is erasing the type parameters of theMap<String, dynamic>
to justMap
. If I manually changeFoo<Map>
toFoo<Map<String, dynamic>>
it fixes the issue. I ran into this whilst mocking elements of the FlutterFire Firestore package which (in its current version) usesMap<String, dynamic>
as a default type, so I can imagine it may cause problems for others too.I did have a look over the documentation/issues and couldn't see anything open to cover this, but I won't be too surprised if I've just tried using something incorrectly.
Thanks!
The text was updated successfully, but these errors were encountered: