- My Software Configuration
- Developing a Vue 3 application
- Utilizing Pinia stores
- Initiating a plugin in my
main.ts
by usingapp.use(myPlugin)
- Creating and providing a repository (
MyRepo
) inMyPlugin.ts
based on specific environment conditions. This repository can interact with an API or provide dummy data for development and testing purposes. - In
myStore.ts
:
defineStore('myStore', () => {
const repo = inject<MyRepoInterface>('myRepo');
// ....
})
- Current Issue
Encountering an error while writing tests that rely on a store which in turn depends on myStore
. When the inject function is invoked in my test, a warning message appears:
[Vue warn]: inject() can only be used within setup() or functional components.
Additionally, the repo
remains undefined
, leading to errors.
- Seeking Solution
On the lookout for a method to provide the repository during the setup of my testing framework (Vitest). By doing so, I aim to inject it into my code during regular application runtime as well as during test execution. Any suggestions on how I can accomplish this?
Open to feedback on my approach to Dependency Injection. Thank you for your input!