File tree Expand file tree Collapse file tree 2 files changed +59
-1
lines changed Expand file tree Collapse file tree 2 files changed +59
-1
lines changed Original file line number Diff line number Diff line change @@ -224,4 +224,61 @@ describe('Testing', () => {
224
224
store . n ++
225
225
expect ( store . double ) . toBe ( 6 )
226
226
} )
227
+
228
+ it ( 'actions are stubbed even when replaced by other plugins' , ( ) => {
229
+ const spy = jest . fn ( )
230
+ mount ( Counter , {
231
+ global : {
232
+ plugins : [
233
+ createTestingPinia ( {
234
+ plugins : [
235
+ ( { store } ) => {
236
+ const { increment } = store . increment
237
+ store . increment = spy
238
+ spy . mockImplementation ( increment )
239
+ } ,
240
+ ] ,
241
+ } ) ,
242
+ ] ,
243
+ } ,
244
+ } )
245
+ const counter = useCounter ( )
246
+
247
+ counter . increment ( )
248
+ counter . increment ( 5 )
249
+ expect ( counter . n ) . toBe ( 0 )
250
+ expect ( counter . increment ) . toHaveBeenCalledTimes ( 2 )
251
+ expect ( counter . increment ) . toHaveBeenLastCalledWith ( 5 )
252
+ // the actual spy is never called because we stub the action
253
+ expect ( spy ) . toHaveBeenCalledTimes ( 0 )
254
+ } )
255
+
256
+ it ( 'pass through replaced actions in plugins' , ( ) => {
257
+ const spy = jest . fn ( )
258
+ mount ( Counter , {
259
+ global : {
260
+ plugins : [
261
+ createTestingPinia ( {
262
+ stubActions : false ,
263
+ plugins : [
264
+ ( { store } ) => {
265
+ const { increment } = store . increment
266
+ store . increment = spy
267
+ spy . mockImplementation ( increment )
268
+ } ,
269
+ ] ,
270
+ } ) ,
271
+ ] ,
272
+ } ,
273
+ } )
274
+ const counter = useCounter ( )
275
+
276
+ counter . increment ( )
277
+ counter . increment ( 5 )
278
+ expect ( counter . n ) . toBe ( 0 )
279
+ expect ( counter . increment ) . toHaveBeenCalledTimes ( 2 )
280
+ expect ( counter . increment ) . toHaveBeenLastCalledWith ( 5 )
281
+ expect ( spy ) . toHaveBeenCalledTimes ( 2 )
282
+ expect ( spy ) . toHaveBeenLastCalledWith ( 5 )
283
+ } )
227
284
} )
Original file line number Diff line number Diff line change @@ -109,7 +109,8 @@ export function createTestingPinia({
109
109
// allow computed to be manually overridden
110
110
pinia . _p . push ( WritableComputed )
111
111
112
- plugins . forEach ( ( plugin ) => pinia . use ( plugin ) )
112
+ // bypass waiting for the app to be installed to ensure the action stubbing happens last
113
+ plugins . forEach ( ( plugin ) => pinia . _p . push ( plugin ) )
113
114
114
115
const createSpy =
115
116
_createSpy ||
You can’t perform that action at this time.
0 commit comments