Skip to content

Need help to test pinia store using router #2239

Closed Answered by ghost23
jbaubree asked this question in Help and Questions
Discussion options

You must be logged in to vote

Hi,

I just had the exact same problem. What solved it for me was to add a fake app (as is actually described in the Pinia documentation in the Testing section), like so:

beforeEach(() => {
  const pinia = createPinia();
  pinia.use(({ store }) => {
    store.router = markRaw(router);
  });
  const app = createApp({}); // <-- !
  app.use(pinia);            // <-- !
  setActivePinia(pinia);
})

Because according to the documentation without an app, plugins (in this case the router) will not actually be added to pinia.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@posva
Comment options

Answer selected by posva
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants