-
| I defined a store like this: // user.ts export const useUserStore = defineStore('user', { state: () => ({ id: 0, }), actions: { logout(to?: RouteLocationRaw|null) { return new Promise((resolve, reject) => { logout().then(response => { this.$reset() const router = useRouter() router.push(to || { path: domainOption.loginRoutePath }) resolve(response) }).catch(error => { reject(error) }) }) }, } })when testing pinia,it won't mount a componet: // user.test.ts describe('userStore', () => { beforeEach(() => { setActivePinia(createPinia()) }) it('logout called router.push ', async () => { const userStore = useUserStore() const router = getRouter() await userStore.logout() expect(router.push).toHaveBeenCalledWith({ path: domainOption.loginRoutePath }) }) })then I got: how to solve it? mount a blank component? that seems no work |
Beta Was this translation helpful? Give feedback.
Answered by posva Oct 18, 2022
Replies: 1 comment 1 reply
-
| See https://pinia.vuejs.org/core-concepts/plugins.html#plugins You cannot call |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by Fallsleep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
See https://pinia.vuejs.org/core-concepts/plugins.html#plugins
You cannot call
useRouter()within the action like you do, that's where theinject()can only be used inside setup error comes from