-
-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integration tests - get_it factories map is lost #76
Comments
Can you show me the test file where you call |
Hi, |
I'm not calling the
and as soon as the application starts running (from within runApp), the first call to |
After converting all import statements for all abstract classes to package references, the problem is solved. |
Please have a look at the explanation here dart-lang/sdk#41868 |
Thank you! |
Hi,
In short: Problem is that registering several factories and singletones on get_it from the integration tests environment (e.g. app.dart file) has no effect and when the application starts running, the internal factories are lost.
In details: Using initServices() on the operational program, I am binding several abstract classes as follows:
GetIt.I.registerLazySingleton<INetworkService>(() => NetworkService()); GetIt.I.registerLazySingleton<ILocalization>(() => LocalizationService());
however, when using the integration tests environment, I would like to bind other implementations, so I'm calling initiServicesTestEnv() before running the app:
GetIt.I.registerLazySingleton<INetworkService>(() => NetworkServiceSimulator()); GetIt.I.registerLazySingleton<ILocalization>(() => LocalizationMock());
but when the test starts running, the following statement fails:
GetIt.I<INetworkService>();
due to the following:
No type INetworkService is registered inside GetIt.
Did you forget to pass an instance name?
(Did you accidentally do GetIt sl=GetIt.instance(); instead of GetIt sl=GetIt.instance;did you forget to register it?)
'package:tw_app/get_it/get_it_impl.dart':
Failed assertion: line 251 pos 14: 'instanceFactory != null'
The text was updated successfully, but these errors were encountered: