]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
docs: match vitest mock
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 9 Oct 2024 09:43:37 +0000 (11:43 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 9 Oct 2024 09:43:37 +0000 (11:43 +0200)
Close #2759, #2796

packages/docs/cookbook/testing.md

index b7bc381a54b324df27baf92a67dcceb28e04c65f..657ae7b4020ca44744b1c2e5211c92078539ba37 100644 (file)
@@ -172,6 +172,7 @@ Actions are automatically spied but type-wise, they are still the regular action
 
 ```ts
 import type { Mock } from 'vitest'
+import type { UnwrapRef } from 'vue'
 import type { Store, StoreDefinition } from 'pinia'
 
 function mockedStore<TStoreDef extends () => unknown>(
@@ -187,15 +188,13 @@ function mockedStore<TStoreDef extends () => unknown>(
       State,
       Record<string, never>,
       {
-        [K in keyof Actions]: Actions[K] extends (
-          ...args: infer Args
-        ) => infer ReturnT
+        [K in keyof Actions]: Actions[K] extends (...args: any[]) => any
           ? // ðŸ‘‡ depends on your testing framework
-            Mock<Args, ReturnT>
+            Mock<Actions[K]>
           : Actions[K]
       }
     > & {
-      [K in keyof Getters]: Getters[K] extends ComputedRef<infer T> ? T : never
+      [K in keyof Getters]: UnwrapRef<Getters[K]>
     }
   : ReturnType<TStoreDef> {
   return useStore() as any