]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
fix(testing): enable initialState witohut app
authorEduardo San Martin Morote <posva13@gmail.com>
Thu, 31 Mar 2022 17:43:29 +0000 (19:43 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Thu, 31 Mar 2022 17:43:29 +0000 (19:43 +0200)
packages/testing/src/initialState.spec.ts
packages/testing/src/testing.ts

index 9b317ff828004bb96c41c3e174d53b6f339c0b27..f3884cccb98f87d50d2d430f25e7d533d654cc64 100644 (file)
@@ -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)
+  })
 })
index adc86d55900a46348a30eec8b254d5a672019585..2699787ea4bdfd5634fea40ebafd51483c822992 100644 (file)
@@ -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])
     }