@@ -2,9 +2,13 @@ import { createPinia, getActivePinia, setActivePinia } from 'pinia'
22import { describe , beforeEach , it , expect , vi } from 'vitest'
33import { createApp } from 'vue'
44import { useMutationCache , isMutationCache } from './mutation-store'
5- import type { UseMutationEntry , MutationCache } from './mutation-store'
5+ import type { UseMutationEntry } from './mutation-store'
66import { flushPromises } from '@vue/test-utils'
7- import type { UseMutationOptions } from './mutation-options'
7+ import {
8+ USE_MUTATION_DEFAULTS ,
9+ type UseMutationOptions ,
10+ type UseMutationOptionsWithDefaults ,
11+ } from './mutation-options'
812import { mockConsoleError , mockWarn } from '../test-utils/mock-warn'
913import { useMutation } from './use-mutation'
1014
@@ -21,9 +25,10 @@ describe('Mutation Cache store', () => {
2125 const mutationCache = useMutationCache ( )
2226 for ( const key of keys ) {
2327 const options = {
28+ ...USE_MUTATION_DEFAULTS ,
2429 key,
2530 mutation : async ( ) => 'ok' ,
26- } satisfies UseMutationOptions
31+ } satisfies UseMutationOptionsWithDefaults
2732 const entry = mutationCache . create ( options )
2833 mutationCache . ensure ( entry , undefined )
2934 }
@@ -116,8 +121,9 @@ describe('Mutation Cache store', () => {
116121 const mutationCache = useMutationCache ( )
117122
118123 const options = {
124+ ...USE_MUTATION_DEFAULTS ,
119125 mutation : async ( ) => 'test' ,
120- } satisfies UseMutationOptions
126+ } satisfies UseMutationOptionsWithDefaults
121127
122128 const entry = mutationCache . create ( options )
123129
@@ -133,6 +139,7 @@ describe('Mutation Cache store', () => {
133139 const mutationCache = useMutationCache ( )
134140 const e1 = mutationCache . ensure (
135141 mutationCache . create ( {
142+ ...USE_MUTATION_DEFAULTS ,
136143 key : [ 'a' , 'b' , 'c' ] ,
137144 mutation : async ( ) => 'abc' ,
138145 } ) ,
@@ -142,6 +149,7 @@ describe('Mutation Cache store', () => {
142149
143150 const e2 = mutationCache . ensure (
144151 mutationCache . create ( {
152+ ...USE_MUTATION_DEFAULTS ,
145153 key : [ 'a' , 'b' , 'd' ] ,
146154 mutation : async ( ) => 'abd' ,
147155 } ) ,
@@ -151,6 +159,7 @@ describe('Mutation Cache store', () => {
151159
152160 const e3 = mutationCache . ensure (
153161 mutationCache . create ( {
162+ ...USE_MUTATION_DEFAULTS ,
154163 key : [ 'a' , 'b' ] ,
155164 mutation : async ( ) => 'ab' ,
156165 } ) ,
@@ -168,6 +177,7 @@ describe('Mutation Cache store', () => {
168177 const mutationCache = useMutationCache ( )
169178 const entry = mutationCache . ensure (
170179 mutationCache . create ( {
180+ ...USE_MUTATION_DEFAULTS ,
171181 key : [ 'a' , 'b' , 'c' ] ,
172182 mutation : async ( ) => 'abc' ,
173183 } ) ,
@@ -208,7 +218,10 @@ describe('Mutation Cache store', () => {
208218 describe ( 'extensibility' , ( ) => {
209219 it ( 'has an ext property that starts empty' , ( ) => {
210220 const mutationCache = useMutationCache ( )
211- const entry = mutationCache . create ( { mutation : async ( ) => 'ok' } )
221+ const entry = mutationCache . create ( {
222+ ...USE_MUTATION_DEFAULTS ,
223+ mutation : async ( ) => 'ok' ,
224+ } )
212225 expect ( entry . ext ) . toBeDefined ( )
213226 } )
214227
@@ -223,7 +236,10 @@ describe('Mutation Cache store', () => {
223236 }
224237 } )
225238
226- const entry = mutationCache . create ( { mutation : async ( ) => 'ok' } )
239+ const entry = mutationCache . create ( {
240+ ...USE_MUTATION_DEFAULTS ,
241+ mutation : async ( ) => 'ok' ,
242+ } )
227243 mutationCache . ensure ( entry , undefined )
228244
229245 expect ( extendSpy ) . toHaveBeenCalledTimes ( 1 )
@@ -240,10 +256,16 @@ describe('Mutation Cache store', () => {
240256 }
241257 } )
242258
243- const entry = mutationCache . create ( { mutation : async ( ) => 'ok' } )
259+ const entry = mutationCache . create ( {
260+ ...USE_MUTATION_DEFAULTS ,
261+ mutation : async ( ) => 'ok' ,
262+ } )
244263 mutationCache . ensure ( entry , undefined )
245264 // Ensure the same entry again
246- const entry2 = mutationCache . create ( { mutation : async ( ) => 'ok' } )
265+ const entry2 = mutationCache . create ( {
266+ ...USE_MUTATION_DEFAULTS ,
267+ mutation : async ( ) => 'ok' ,
268+ } )
247269 mutationCache . ensure ( entry2 , undefined )
248270
249271 // extend should be called twice (once per unique entry)
@@ -262,7 +284,10 @@ describe('Mutation Cache store', () => {
262284 }
263285 } )
264286
265- const entry = mutationCache . create ( { mutation : async ( ) => 'ok' } )
287+ const entry = mutationCache . create ( {
288+ ...USE_MUTATION_DEFAULTS ,
289+ mutation : async ( ) => 'ok' ,
290+ } )
266291 mutationCache . ensure ( entry , undefined )
267292
268293 expect ( entry . ext ) . toHaveProperty ( 'customProperty' , 'test-value' )
@@ -300,6 +325,7 @@ describe('Mutation Cache store', () => {
300325 const mutationCache = useMutationCache ( )
301326 const entry = mutationCache . ensure (
302327 mutationCache . create ( {
328+ ...USE_MUTATION_DEFAULTS ,
303329 key : [ 'a' , 'b' , 'c' ] ,
304330 mutation : async ( ) => 'abc' ,
305331 } ) ,
@@ -313,9 +339,10 @@ describe('Mutation Cache store', () => {
313339 it ( 'can store and retrieve multiple entries with the same user key' , ( ) => {
314340 const mutationCache = useMutationCache ( )
315341 const options = {
342+ ...USE_MUTATION_DEFAULTS ,
316343 key : [ 'same' , 'key' ] ,
317344 mutation : async ( ) => 'ok' ,
318- } satisfies UseMutationOptions
345+ } satisfies UseMutationOptionsWithDefaults
319346
320347 const entry1 = mutationCache . ensure ( mutationCache . create ( options ) , undefined )
321348 const entry2 = mutationCache . ensure ( mutationCache . create ( options ) , undefined )
@@ -342,11 +369,17 @@ describe('Mutation Cache store', () => {
342369 const mutationCache = useMutationCache ( )
343370
344371 const entry1 = mutationCache . ensure (
345- mutationCache . create ( { mutation : async ( ) => 'ok' } ) ,
372+ mutationCache . create ( {
373+ ...USE_MUTATION_DEFAULTS ,
374+ mutation : async ( ) => 'ok' ,
375+ } ) ,
346376 undefined ,
347377 )
348378 const entry2 = mutationCache . ensure (
349- mutationCache . create ( { mutation : async ( ) => 'ok' } ) ,
379+ mutationCache . create ( {
380+ ...USE_MUTATION_DEFAULTS ,
381+ mutation : async ( ) => 'ok' ,
382+ } ) ,
350383 undefined ,
351384 )
352385
0 commit comments