jonataslaw / getx

Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
MIT License
10.37k stars 1.63k forks source link

Get.testMode = true is ineffective #790

Closed Presheda closed 3 years ago

Presheda commented 3 years ago

unable to run navigation test as Get.testMode is ineffective

` test("test description", () async {

  SplashScreenController controller = SplashScreenController();
  await controller.fetchData();

});

Screenshot (115)

`

jonataslaw commented 3 years ago

Please provide a reproduction code

Presheda commented 3 years ago

Steps to reproduce

SplashScreenController

import 'package:deggia_regular/ui/route/route_names.dart';
import 'package:deggia_regular/ui/views/home/home_screen.dart';
import 'package:deggia_regular/utils/locator.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class SplashScreenController extends GetxController {
  StorageService storageService = locator<StorageService>();

  @override
  void onInit() {
    super.onInit();
    fetchData();
  }

  Future fetchData() async {
    Get.testMode = true;
    bool isFirstTime = await storageService.firstTime();
    if (isFirstTime) {
      await storageService.setFirstTime();
      await Get.offAndToNamed(RouteName.on_boarding);
    } else {
      await Get.offAllNamed(RouteName.homepage);
    }
  }
}
group("first_time_load", () {
    setUp(() {
        var service = StorageServiceMock();

  when(service.firstTime()).thenAnswer((realInvocation) async => true);
  when(service.isLightMode()).thenAnswer((realInvocation) async => true);

  locator.registerFactory<StorageService>(() => service);
    });

    test("test description", () async {
      SplashScreenController controller = SplashScreenController();
      await controller.fetchData();
    });
}
)