Closed Ricardo1980 closed 5 years ago
Well, I found another way, I think it make sense. Basically, I delegate all dependency injection to the coordinators, then, when testing a specific view controller/view model, I pass a coordinator that is a subclass of the original coordinator but using makes. Doing that, I don't use the enum for passing dependencies, just relevant parameters (like ids or whatever). What do you think?
I'm not sure about what you mean exactly, but what we often do is to create services in the coordinator rather than in (often unrelated) viewModels. That way, you can simply take a look at the coordinators to change any services. If that becomes too complicated and confusing, there is also the possibility of introducing a serviceFactory or serviceLocator, which is only known to the coordinators.
Thanks @pauljohanneskraft I was creating the services in the view models, and that was a problem. Now I moved that to the coordinators, and then I can test everything properly, I only have to inject a mock coordinator.
Hello,
There is something I don't know exactly how to do.
My view models have a list of dependencies in the initialiser, same for the enums in the route. So, I have something like:
And the coordinator is:
You can see how I pass my dependencies. The problem I have is that sometimes the view mode calls something like:
Which means that I cannot test that scenario properly, because I cannot pass mocks. Check "service: BudgetService()", that is not a mock, but a real service.
How should I manage that? Should I pass to my view model all dependencies? I mean, even the ones that are going to be called when opening other view models when calling trigger (XCoordinator)?
Thanks a lot for suggestions.