Elementary-team / flutter-elementary

This is a home to a family of Elementary library packages.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WidgetModel Tests fail on Flutter 3.10 - NoSuchMethodError: has no instance setter '_wmHandler='

Sadhorsephile opened this issue · comments

Steps to reproduce

  1. Create basic ElementaryModel - WidgetModel - ElementaryWidget.
  2. Create test for WidgetModel.
  3. Invoke tester.init() in testFunction inside testWidgetModel.

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':.
Screenshot image
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 {}

Hi. Try to use MockElementaryModelMixin for testing, this behavior is related to changes in the 2.19 Dart. More details here