Skip to content

Commit ad90fd2

Browse files
committed
fix(testing): allow overriding plugin computed properties
1 parent 0f789fe commit ad90fd2

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

packages/testing/src/testing.spec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,4 +281,35 @@ describe('Testing', () => {
281281
expect(spy).toHaveBeenCalledTimes(2)
282282
expect(spy).toHaveBeenLastCalledWith(5)
283283
})
284+
285+
it('can override computed added in plugins', () => {
286+
const pinia = createTestingPinia({
287+
plugins: [
288+
({ store }) => {
289+
store.triple = computed(() => store.n * 3)
290+
},
291+
],
292+
})
293+
294+
const store = useCounter(pinia)
295+
store.n++
296+
// @ts-expect-error: non declared
297+
expect(store.triple).toBe(3)
298+
// once the getter is overridden, it stays
299+
// @ts-expect-error: non declared
300+
store.triple = 10
301+
// @ts-expect-error: non declared
302+
expect(store.triple).toBe(10)
303+
store.n++
304+
// @ts-expect-error: non declared
305+
expect(store.triple).toBe(10)
306+
// it can be set to undefined again to reset
307+
// @ts-expect-error
308+
store.triple = undefined
309+
// @ts-expect-error: non declared
310+
expect(store.triple).toBe(6)
311+
store.n++
312+
// @ts-expect-error: non declared
313+
expect(store.triple).toBe(9)
314+
})
284315
})

packages/testing/src/testing.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ export function createTestingPinia({
106106
}
107107
})
108108

109-
// allow computed to be manually overridden
110-
pinia._p.push(WritableComputed)
111-
112109
// bypass waiting for the app to be installed to ensure the action stubbing happens last
113110
plugins.forEach((plugin) => pinia._p.push(plugin))
114111

112+
// allow computed to be manually overridden
113+
pinia._p.push(WritableComputed)
114+
115115
const createSpy =
116116
_createSpy ||
117117
(typeof jest !== 'undefined' && jest.fn) ||

0 commit comments

Comments
 (0)