41 lines
1.1 KiB
Cheetah
41 lines
1.1 KiB
Cheetah
---
|
|
description: "GetX testing conventions for {{PROJECT_NAME}}"
|
|
alwaysApply: false
|
|
---
|
|
|
|
# GetX Testing Standards — {{PROJECT_NAME}}
|
|
|
|
## Test pattern
|
|
```dart
|
|
void main() {
|
|
late ProductsController controller;
|
|
late MockProductRepository mockRepo;
|
|
|
|
setUp(() {
|
|
mockRepo = MockProductRepository();
|
|
Get.testMode = true;
|
|
controller = Get.put(ProductsController(mockRepo));
|
|
});
|
|
|
|
tearDown(() => Get.deleteAll());
|
|
|
|
test('loads products on init', () async {
|
|
when(() => mockRepo.getProducts()).thenAnswer((_) async => [fakeProduct]);
|
|
await controller.fetchProducts();
|
|
expect(controller.products, [fakeProduct]);
|
|
expect(controller.isLoading.value, false);
|
|
});
|
|
|
|
testWidgets('ProductsView shows shimmer while loading', (tester) async {
|
|
controller.isLoading.value = true;
|
|
await tester.pumpWidget(GetMaterialApp(home: ProductsView()));
|
|
expect(find.byType(ProductShimmer), findsOneWidget);
|
|
});
|
|
}
|
|
```
|
|
|
|
## Rules
|
|
- Use `Get.testMode = true` in setUp
|
|
- Always call `Get.deleteAll()` in tearDown
|
|
- Wrap widget tests in `GetMaterialApp`, not `MaterialApp`
|