WidgetModel Tests fail on Flutter 3.10 - NoSuchMethodError: has no instance setter '_wmHandler='
Sadhorsephile opened this issue · comments
Сергей Паршонок commented
Steps to reproduce
- Create basic
ElementaryModel
-WidgetModel
-ElementaryWidget
. - Create test for
WidgetModel
. - Invoke
tester.init()
intestFunction
insidetestWidgetModel
.
Expected result
Tests will not fail.
Actual result
Tests will fail with error:
NoSuchMethodError: Class 'ExampleModelMock' has no instance setter '_wmHandler='.
Receiver: Instance of 'ExampleModelMock'
Tried calling: _wmHandler=Closure: (Object) => void from Function 'onErrorHandle':.
Code example
import 'package:elementary/elementary.dart';
import 'package:elementary_test/elementary_test.dart';
import 'package:flutter/material.dart';
import 'package:mocktail/mocktail.dart';
class ExampleModel extends ElementaryModel {}
class ExampleWidget extends ElementaryWidget<IExampleWidgetModel> {
const ExampleWidget({
Key? key,
WidgetModelFactory wmFactory = defaultExampleWidgetModelFactory,
}) : super(wmFactory, key: key);
@override
Widget build(IExampleWidgetModel wm) {
return Container();
}
}
abstract class IExampleWidgetModel extends IWidgetModel {}
ExampleWidgetModel defaultExampleWidgetModelFactory(BuildContext context) {
return ExampleWidgetModel(ExampleModel());
}
class ExampleWidgetModel extends WidgetModel<ExampleWidget, ExampleModel>
implements IExampleWidgetModel {
ExampleWidgetModel(ExampleModel model) : super(model);
}
/// Тесты для [ExampleWidgetModel]
void main() {
late ExampleModelMock model;
ExampleWidgetModel setUpWm() {
model = ExampleModelMock();
return ExampleWidgetModel(model);
}
testWidgetModel<ExampleWidgetModel, ExampleWidget>(
'myfirsttestcase',
setUpWm,
(wm, tester, context) {
tester.init();
},
);
testWidgetModel<ExampleWidgetModel, ExampleWidget>(
'mysecondtestcase',
setUpWm,
(wm, tester, context) {
tester.init();
},
);
}
class ExampleModelMock extends Mock implements ExampleModel {}
Mikhail Zotyev commented
Hi. Try to use MockElementaryModelMixin
for testing, this behavior is related to changes in the 2.19 Dart. More details here