Open shivamtiwari-ttn opened 1 month ago
For those who are facing such issue, I was able to pass the test cases by making below change in my test file.
I have replaced
const channel = MethodChannel('wakelock_macos');
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
return null;
});
to
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMessageHandler(
'dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.toggle',
(obj) async => obj);
I am using wakelock_plus for one of my classes to keep player screen on. Test cases related to that file are failing. I was earlier using wakelock, recently updated to wakelock_plus. In the test case file I have a setupAll method where earlier for wakelock 'wakelock_macos' was used for MethodChannel name like below.
for this test cases were passed successfully.
After comparing the wakelock and wakelock_plus libraries, I attempted to utilise the MethodChannel named 'wakelock_plus_macos' for wakelock_plus in the same way that we used it for wakelock.
const channel = MethodChannel('wakelock_plus_macos');
But test cases are failing with below error:
PlatformException(channel-error, Unable to establish connection on channel: "dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.toggle"., null, null)
Now if I use 'dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.toggle' as the MethodChannel name like
const channel = MethodChannel('dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.toggle');
I am getting another error:
What should be used for MethodChannel to run test cases successfully