Skip to content

Commit 0a99a75

Browse files
committed
fix(testing): enable initialState witohut app
1 parent f4db826 commit 0a99a75

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

packages/testing/src/initialState.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,17 @@ describe('Testing: initial state', () => {
5757
counter.nested.n++
5858
expect(counter.nested.n).toBe(11)
5959
})
60+
61+
it('can set an initial state with no app', () => {
62+
const pinia = createTestingPinia({
63+
initialState: {
64+
counter: { n: 20 },
65+
},
66+
})
67+
const counter = useCounter(pinia)
68+
expect(counter.nested).toEqual({ n: 0, other: false })
69+
expect(counter.n).toBe(20)
70+
counter.n++
71+
expect(counter.n).toBe(21)
72+
})
6073
})

packages/testing/src/testing.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ export function createTestingPinia({
9999
}: TestingOptions = {}): TestingPinia {
100100
const pinia = createPinia()
101101

102-
pinia.use(({ store }) => {
102+
// allow adding initial state
103+
pinia._p.push(({ store }) => {
103104
if (initialState[store.$id]) {
104105
mergeReactiveObjects(store.$state, initialState[store.$id])
105106
}

0 commit comments

Comments
 (0)