Showing
1 changed file
with
34 additions
and
0 deletions
| 1 | import 'package:flutter_test/flutter_test.dart'; | 1 | import 'package:flutter_test/flutter_test.dart'; | 
| 2 | +import 'package:matcher/matcher.dart'; | ||
| 2 | import 'package:get/get.dart'; | 3 | import 'package:get/get.dart'; | 
| 3 | 4 | ||
| 4 | class Mock { | 5 | class Mock { | 
| @@ -10,6 +11,14 @@ class Mock { | @@ -10,6 +11,14 @@ class Mock { | ||
| 10 | 11 | ||
| 11 | class Controller {} | 12 | class Controller {} | 
| 12 | 13 | ||
| 14 | +class DisposableController extends DisposableInterface { | ||
| 15 | + bool initialized = false; | ||
| 16 | + | ||
| 17 | + void onInit() async { | ||
| 18 | + initialized = true; | ||
| 19 | + } | ||
| 20 | +} | ||
| 21 | + | ||
| 13 | abstract class Service { | 22 | abstract class Service { | 
| 14 | String post(); | 23 | String post(); | 
| 15 | } | 24 | } | 
| @@ -59,4 +68,29 @@ void main() { | @@ -59,4 +68,29 @@ void main() { | ||
| 59 | expect(ct1 == ct2, false); | 68 | expect(ct1 == ct2, false); | 
| 60 | Get.reset(); | 69 | Get.reset(); | 
| 61 | }); | 70 | }); | 
| 71 | + | ||
| 72 | + group('test put, delete and check onInit execution', () { | ||
| 73 | + tearDownAll(() { | ||
| 74 | + Get.reset(); | ||
| 75 | + }); | ||
| 76 | + | ||
| 77 | + test('Get.put test with init check', () async { | ||
| 78 | + final instance = Get.put<DisposableController>(DisposableController()); | ||
| 79 | + expect(instance, Get.find<DisposableController>()); | ||
| 80 | + expect(instance.initialized, true); | ||
| 81 | + }); | ||
| 82 | + | ||
| 83 | + test('Get.delete test with disposable controller', () async { | ||
| 84 | + expect(await Get.delete<DisposableController>(), true); | ||
| 85 | + expect(() => Get.find<DisposableController>(), | ||
| 86 | + throwsA(TypeMatcher<String>())); | ||
| 87 | + }); | ||
| 88 | + | ||
| 89 | + test('Get.put test after delete with disposable controller and init check', | ||
| 90 | + () async { | ||
| 91 | + final instance = Get.put<DisposableController>(DisposableController()); | ||
| 92 | + expect(instance, Get.find<DisposableController>()); | ||
| 93 | + expect(instance.initialized, true); | ||
| 94 | + }); | ||
| 95 | + }); | ||
| 62 | } | 96 | } | 
- 
Please register or login to post a comment