【发布时间】:2021-05-03 15:41:33
【问题描述】:
下面的代码曾经在 null 安全之前工作,但现在我得到“type 'Null' is not a subtype of type 'Future
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
class MockMethodChannel extends Mock implements MethodChannel {}
void main() {
group('all', () {
test('test', () async {
final mockMethodChannel = MockMethodChannel();
when(mockMethodChannel
.invokeMethod<String>("GET com.eight/preference-management/preferences"))
.thenAnswer((_) async => "test");
});
});
}
【问题讨论】:
-
我们在 mockito 中添加了 null 安全性,更改了类的模拟,看看这个,我一直在努力解决它:github.com/dart-lang/mockito/issues/403,你也可以看看文档: github.com/dart-lang/mockito/blob/master/NULL_SAFETY_README.md,切换有点麻烦,如果您需要进一步的帮助,请告诉我。
-
效果很好,非常感谢!只需添加以下内容,一切都很好:` import 'preference_datasource_test.mocks.dart'; @GenerateMocks([], customMocks: [MockSpec
(as: #MockMethodChannel)]) ` -
太棒了!!我很高兴你设法解决了这个问题!
-
有没有机会支持我的评论?