From: Eduardo San Martin Morote Date: Mon, 25 Apr 2022 13:11:55 +0000 (+0200) Subject: fix(testing): allow overriding plugin computed properties X-Git-Tag: @pinia/nuxt@0.1.9~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ad90fd24eecca8bd7bff238bcfa039e1a0a7f3d5;p=thirdparty%2Fvuejs%2Fpinia.git fix(testing): allow overriding plugin computed properties --- diff --git a/packages/testing/src/testing.spec.ts b/packages/testing/src/testing.spec.ts index 4b0b4364..ef1b2069 100644 --- a/packages/testing/src/testing.spec.ts +++ b/packages/testing/src/testing.spec.ts @@ -281,4 +281,35 @@ describe('Testing', () => { expect(spy).toHaveBeenCalledTimes(2) expect(spy).toHaveBeenLastCalledWith(5) }) + + it('can override computed added in plugins', () => { + const pinia = createTestingPinia({ + plugins: [ + ({ store }) => { + store.triple = computed(() => store.n * 3) + }, + ], + }) + + const store = useCounter(pinia) + store.n++ + // @ts-expect-error: non declared + expect(store.triple).toBe(3) + // once the getter is overridden, it stays + // @ts-expect-error: non declared + store.triple = 10 + // @ts-expect-error: non declared + expect(store.triple).toBe(10) + store.n++ + // @ts-expect-error: non declared + expect(store.triple).toBe(10) + // it can be set to undefined again to reset + // @ts-expect-error + store.triple = undefined + // @ts-expect-error: non declared + expect(store.triple).toBe(6) + store.n++ + // @ts-expect-error: non declared + expect(store.triple).toBe(9) + }) }) diff --git a/packages/testing/src/testing.ts b/packages/testing/src/testing.ts index 11f85f41..7afaadfb 100644 --- a/packages/testing/src/testing.ts +++ b/packages/testing/src/testing.ts @@ -106,12 +106,12 @@ export function createTestingPinia({ } }) - // allow computed to be manually overridden - pinia._p.push(WritableComputed) - // bypass waiting for the app to be installed to ensure the action stubbing happens last plugins.forEach((plugin) => pinia._p.push(plugin)) + // allow computed to be manually overridden + pinia._p.push(WritableComputed) + const createSpy = _createSpy || (typeof jest !== 'undefined' && jest.fn) ||