Files
easy_settings_screen/test/easy_settings_screen_test.dart
2025-07-23 14:17:58 +02:00

32 lines
927 B
Dart
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
const channel = MethodChannel('easy_settings_screen');
testWidgets('mock platform channel', (WidgetTester tester) async {
// 1⃣ Initialize the test binding
TestWidgetsFlutterBinding.ensureInitialized();
// 2⃣ Set up the mock directly on the defaultBinaryMessenger
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(channel, (
MethodCall call,
) async {
return '42';
});
// Perform widget actions that trigger the method call...
// e.g., pump your widget or call the method manually.
// ✅ Verify behavior, e.g.:
final result = await channel.invokeMethod('anyMethod');
expect(result, '42');
// 3⃣ Clean up after test
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
channel,
null,
);
});
}