From 62e10a1f4eff25b4c31becd923876c68452d281d Mon Sep 17 00:00:00 2001 From: littleGnAl Date: Fri, 9 Aug 2024 15:13:09 +0800 Subject: [PATCH] feat: Add throwExceptionHandler --- test/iris_method_channel_test.dart | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/iris_method_channel_test.dart b/test/iris_method_channel_test.dart index eaedb2c..3bd6edf 100644 --- a/test/iris_method_channel_test.dart +++ b/test/iris_method_channel_test.dart @@ -867,4 +867,32 @@ void main() { await irisMethodChannel.dispose(); }, ); + + test( + 'throwExceptionHandler throw Exception by default', + () async { + final currentThrowExceptionHandler = throwExceptionHandler; + + expect(() => throwExceptionHandler(code: 1, message: 'message'), + throwsA(isA())); + + throwExceptionHandler = currentThrowExceptionHandler; + }, + ); + + test( + 'Can override throwExceptionHandler', + () async { + final currentThrowExceptionHandler = throwExceptionHandler; + + throwExceptionHandler = ({required int code, String? message}) { + throw StateError('message'); + }; + + expect(() => throwExceptionHandler(code: 1, message: 'message'), + throwsA(isA())); + + throwExceptionHandler = currentThrowExceptionHandler; + }, + ); }