File tree 3 files changed +25
-2
lines changed 3 files changed +25
-2
lines changed Original file line number Diff line number Diff line change 5
5
* Allow generating a mock class which includes overriding members with private
6
6
types in their signature. Such members cannot be stubbed with mockito, and
7
7
will only be generated when specified in MockSpec ` unsupportedMembers ` .
8
+ * Include ` required ` keyword in functions used as default return values.
8
9
9
10
## 5.3.0
10
11
Original file line number Diff line number Diff line change @@ -1492,7 +1492,11 @@ class _MockClassInfo {
1492
1492
superParameterType: parameter.type, defaultName: '__p$position ' );
1493
1493
b.optionalParameters.add (matchingParameter);
1494
1494
position++ ;
1495
- } else if (parameter.isNamed) {
1495
+ } else if (parameter.isOptionalNamed) {
1496
+ final matchingParameter =
1497
+ _matchingParameter (parameter, superParameterType: parameter.type);
1498
+ b.optionalParameters.add (matchingParameter);
1499
+ } else if (parameter.isRequiredNamed) {
1496
1500
final matchingParameter =
1497
1501
_matchingParameter (parameter, superParameterType: parameter.type);
1498
1502
b.optionalParameters.add (matchingParameter);
@@ -1595,6 +1599,7 @@ class _MockClassInfo {
1595
1599
_typeReference (superParameterType, forceNullable: forceNullable);
1596
1600
}
1597
1601
if (parameter.isNamed) pBuilder.named = true ;
1602
+ if (parameter.isRequiredNamed) pBuilder.required = true ;
1598
1603
if (parameter.defaultValueCode != null ) {
1599
1604
try {
1600
1605
pBuilder.defaultTo = _expressionFromDartObject (
Original file line number Diff line number Diff line change @@ -1524,7 +1524,7 @@ void main() {
1524
1524
void m({required covariant int a});
1525
1525
}
1526
1526
''' ),
1527
- _containsAllOf ('void m({num? a}) => super.noSuchMethod(' ),
1527
+ _containsAllOf ('void m({required num? a}) => super.noSuchMethod(' ),
1528
1528
);
1529
1529
});
1530
1530
@@ -2455,6 +2455,23 @@ void main() {
2455
2455
);
2456
2456
});
2457
2457
2458
+ test (
2459
+ 'creates a dummy non-null function-typed return value, with required '
2460
+ 'named parameters' , () async {
2461
+ await expectSingleNonNullableOutput (
2462
+ dedent (r'''
2463
+ abstract class Foo {
2464
+ void Function(Foo, {required bool b}) m();
2465
+ }
2466
+ ''' ),
2467
+ _containsAllOf ('''
2468
+ returnValue: (
2469
+ _i2.Foo __p0, {
2470
+ required bool b,
2471
+ }) {},''' ),
2472
+ );
2473
+ });
2474
+
2458
2475
test (
2459
2476
'creates a dummy non-null function-typed return value, with non-core '
2460
2477
'return type' , () async {
You can’t perform that action at this time.
0 commit comments