From: Eduardo San Martin Morote Date: Thu, 31 Mar 2022 17:43:29 +0000 (+0200) Subject: fix(testing): enable initialState witohut app X-Git-Tag: @pinia/testing@0.0.11~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0a99a7589bed28104e26fccfa4fad007d73f4ca1;p=thirdparty%2Fvuejs%2Fpinia.git fix(testing): enable initialState witohut app --- diff --git a/packages/testing/src/initialState.spec.ts b/packages/testing/src/initialState.spec.ts index 9b317ff8..f3884ccc 100644 --- a/packages/testing/src/initialState.spec.ts +++ b/packages/testing/src/initialState.spec.ts @@ -57,4 +57,17 @@ describe('Testing: initial state', () => { counter.nested.n++ expect(counter.nested.n).toBe(11) }) + + it('can set an initial state with no app', () => { + const pinia = createTestingPinia({ + initialState: { + counter: { n: 20 }, + }, + }) + const counter = useCounter(pinia) + expect(counter.nested).toEqual({ n: 0, other: false }) + expect(counter.n).toBe(20) + counter.n++ + expect(counter.n).toBe(21) + }) }) diff --git a/packages/testing/src/testing.ts b/packages/testing/src/testing.ts index adc86d55..2699787e 100644 --- a/packages/testing/src/testing.ts +++ b/packages/testing/src/testing.ts @@ -99,7 +99,8 @@ export function createTestingPinia({ }: TestingOptions = {}): TestingPinia { const pinia = createPinia() - pinia.use(({ store }) => { + // allow adding initial state + pinia._p.push(({ store }) => { if (initialState[store.$id]) { mergeReactiveObjects(store.$state, initialState[store.$id]) }