Services wrapper for Plugins on Angular (or other Frameworks) are not available. Preventing dependency injection and good testing.
Libraries for main frameworks (Angular, React, Vue) should be released, providing wrapping service to be able to inject the plugins in other classes to allow for testing and better maintainability (lazy loading, code analysis...)
I don't know if it is the right repository to post this issue, but I could not think of another one.
Issues tagged with feature request are closed but tracked for reactions to gauge interest.
My opinion: Since Capacitor is framework agnostic, I think this should be a separate project/repo as it was done with capacitor react hooks https://github.com/ionic-team/ionic-react-hooks
I agree with you, it should be a separate project but I did not find a better place to talk about the feature.
I also wanted to make sure that it did not already existed as I took sometime to look for it but could not find anything on the web.
It seems a great idea. I just started a new project and it's boring to wrap every single plugins into an Angular services just in order to test my code.
In the interim, I wouldn't go to the extreme of creating a bunch of boring injectable services just in order to test your code.
You can just replace the items on Plugins as such: https://github.com/ionic-team/iv-training-starter/blob/master/src/app/app.component.spec.ts#L11-L25
Use them in your test the usual way: https://github.com/ionic-team/iv-training-starter/blob/master/src/app/app.component.spec.ts#L34-L38
And just keep your code using the objects on Plugins the way that it is: https://github.com/ionic-team/iv-training-starter/blob/master/src/app/app.component.ts#L17-L24
No services needed.
Totally agree that it would be nice to have them, though. It would make the testing more "natural", but it certainly isn't a requirement in many cases.
@kensodemann Thanks, I don't know why I thought they were const.
But finally, I start to love my injectable services (it's maybe my OCD side). I think, that to have my plugins injected in the constructor, is more readable/maintainable to know what a component does.
Most helpful comment
In the interim, I wouldn't go to the extreme of creating a bunch of boring injectable services just in order to test your code.
You can just replace the items on
Pluginsas such: https://github.com/ionic-team/iv-training-starter/blob/master/src/app/app.component.spec.ts#L11-L25Use them in your test the usual way: https://github.com/ionic-team/iv-training-starter/blob/master/src/app/app.component.spec.ts#L34-L38
And just keep your code using the objects on
Pluginsthe way that it is: https://github.com/ionic-team/iv-training-starter/blob/master/src/app/app.component.ts#L17-L24No services needed.
Totally agree that it would be nice to have them, though. It would make the testing more "natural", but it certainly isn't a requirement in many cases.