Pinia plugins not working inside tests #3003
Replies: 2 comments 2 replies
-
You need the store to be used within an app to have plugins (they pass the app instance) |
Beta Was this translation helpful? Give feedback.
1 reply
-
import { it, expect, vi } from 'vitest';
import { createPinia, setActivePinia, defineStore } from 'pinia';
import { createApp, defineComponent, h, KeepAlive } from 'vue';
it('tests', async () => {
const foo = vi.fn();
const pinia = createPinia().use(({ store }) => foo(store.$id));
setActivePinia(pinia);
createApp(defineComponent(() => () => h(KeepAlive, {}))).use(pinia); // this is needed for the store to work
const useTestStore = defineStore('store', { state: () => ({ foo: 1 }) });
const store = useTestStore();
expect(foo).toHaveBeenCalled();
}); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
leonheess
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Even the most basic plugin fails in a test environment:
Here is a minimal reproduction: https://stackblitz.com/edit/github-ofdqvmtu?file=test.test.ts
Beta Was this translation helpful? Give feedback.
All reactions