From 5be65eb53fd588fd3e842bdc41b484dab558fc68 Mon Sep 17 00:00:00 2001 From: Keith Charles Date: Mon, 4 Apr 2022 15:11:49 -0600 Subject: [PATCH] add a way to reassign pinia getters in vue 2 --- packages/testing/src/testing.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/testing/src/testing.ts b/packages/testing/src/testing.ts index 2699787ea4..d16478b05e 100644 --- a/packages/testing/src/testing.ts +++ b/packages/testing/src/testing.ts @@ -197,17 +197,19 @@ function isComputed( return !!v && isRef(v) && 'effect' in v } -function WritableComputed({ store }: PiniaPluginContext) { +function WritableComputed({ store, options }: PiniaPluginContext) { const rawStore = toRaw(store) for (const key in rawStore) { const value = rawStore[key] - if (isComputed(value)) { + // Vue2 store getters are not refs and can't be found with isComputed() + const isVue2Getter = isVue2 && options.getters?.[key] + if (isComputed(value) || isVue2Getter) { rawStore[key] = customRef((track, trigger) => { let internalValue: any return { get: () => { track() - return internalValue !== undefined ? internalValue : value.value + return internalValue !== undefined ? internalValue : (isVue2Getter ? value : value.value) }, set: (newValue) => { internalValue = newValue