From fbb1a56fe46df6fb99e04f45be4d2969fe99d8fc Mon Sep 17 00:00:00 2001 From: OnlyWick Date: Tue, 13 Feb 2024 17:27:52 +0800 Subject: [PATCH] fix: @pinia/nuxt breaks createTestingPinia fix #2555 --- packages/testing/src/testing.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/testing/src/testing.ts b/packages/testing/src/testing.ts index 0b4db94f57..54217269f9 100644 --- a/packages/testing/src/testing.ts +++ b/packages/testing/src/testing.ts @@ -106,7 +106,10 @@ export function createTestingPinia({ fakeApp = false, createSpy: _createSpy, }: TestingOptions = {}): TestingPinia { - const pinia = createPinia() + const app: App = (globalThis as any).__unctx__.get('nuxt-app').tryUse().vueApp + const symbols = Object.getOwnPropertySymbols(app._context.provides) + const nuxtPinia: Pinia = app._context.provides[symbols[0]] + const pinia = nuxtPinia ?? createPinia() // allow adding initial state pinia._p.push(({ store }) => {