File tree Expand file tree Collapse file tree 2 files changed +34
-3
lines changed Expand file tree Collapse file tree 2 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -281,4 +281,35 @@ describe('Testing', () => {
281
281
expect ( spy ) . toHaveBeenCalledTimes ( 2 )
282
282
expect ( spy ) . toHaveBeenLastCalledWith ( 5 )
283
283
} )
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
+ } )
284
315
} )
Original file line number Diff line number Diff line change @@ -106,12 +106,12 @@ export function createTestingPinia({
106
106
}
107
107
} )
108
108
109
- // allow computed to be manually overridden
110
- pinia . _p . push ( WritableComputed )
111
-
112
109
// bypass waiting for the app to be installed to ensure the action stubbing happens last
113
110
plugins . forEach ( ( plugin ) => pinia . _p . push ( plugin ) )
114
111
112
+ // allow computed to be manually overridden
113
+ pinia . _p . push ( WritableComputed )
114
+
115
115
const createSpy =
116
116
_createSpy ||
117
117
( typeof jest !== 'undefined' && jest . fn ) ||
You can’t perform that action at this time.
0 commit comments