Open Vildnex opened 10 months ago
Hey @Vildnex have you considered using a register module to register your third-party dependencies?
@Milad-Akarie sorry for the delay. I'm not sure how to do this or what exactly do you mean, could you give me an example?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions
@Milad-Akarie so could you provide me an example of any sort? I still have this issue and I could not find anything on how to fix it.
Hey @Vildnex sorry for the delay I've been too busy. Why not do it the other way around? keep your lib folder clean of mocks and inside the test folder generate your mocks with everything else from the lib folder
inside of your test folder:
final getIt = GetIt.instance;
@InjectableInit(
generateForDir: ['lib', 'test'], // process files inside both folders
preferRelativeImports: true, // because classes inside of the test folder can not be package-imports
initializerName: 'initTest' // optional name to avoid confusion with the main init method
)
void main() async {
await getIt.initTest(environment: Environment.test);
print(getIt<MockableService>());
}
@test
@Injectable(as: MockableService)
class ServiceMock extends MockableService{
void doSomething() {
print('mocked');
}
}
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions
@Milad-Akarie sorry also for this delay this the right thing that I needed. Thank you so much for help 😁🎉
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions
I've read the documentation few times already and so far I understand is that I can use injectable for anything which is is "lib" folder, or any other folder if is specify by
generateForDir
on@InjectableInit
but here is the problem... I can not access anything which is into the test folder, in my case this been all the mocks for all the classes.Example (If I already have the 2 classes inside my lib folder):
But in my case I am using a 3d party library for my backend service called
[Parse Server](https://pub.dev/packages/parse_server_sdk)
. I am not sure how exactly to do:I have a class ParseObject from this library and also a Mock class for this (which is inside of
test
folder. How can I create a injection, such that I can callgetIt<ParseObject>().doSomething()
and return a MockParseObject if it is test enviroment, or a ParseObject if is a dev enviroment.Because when I initialize the injectable, I have to tell him this part "@LazySingleton(as: Service, env: [Environment.test])" or any other in this regard, how can I keep my Mock inside in my test folder without interfiring with the lib folder?
Is there any alternative of doing it into a much nice form then this (which also dose not work because I cant import the Mock class from test folder into the lib folder)
I've try to find any example for this situations but I think either the documentation is not clear enought, or I think I am missing something. Could any of you guys help me whit this?