]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
test: fix type
authorEduardo San Martin Morote <posva13@gmail.com>
Thu, 24 Jun 2021 10:34:04 +0000 (12:34 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Thu, 24 Jun 2021 13:18:53 +0000 (15:18 +0200)
__tests__/storePlugins.spec.ts

index 4bd9431bdc3695fd643a5e92b0587633640c4dad..b74050e24b5246fefcb9bc9f8189cdae42b6cc1f 100644 (file)
@@ -1,6 +1,6 @@
 import { createPinia, defineStore, PiniaPlugin } from '../src'
 import { createLocalVue, mount } from '@vue/test-utils'
-import { ref, set } from '@vue/composition-api'
+import { ref, set, toRef } from '@vue/composition-api'
 
 declare module '../src' {
   export interface PiniaCustomProperties<Id> {
@@ -10,6 +10,12 @@ declare module '../src' {
     idFromPlugin: Id
     someRef: number
   }
+
+  export interface PiniaCustomStateProperties<S> {
+    // pluginN: 'test' extends Id ? number : never | undefined
+    pluginN: number
+    someRef: number
+  }
 }
 
 describe('store plugins', () => {
@@ -34,8 +40,13 @@ describe('store plugins', () => {
     mount({ template: '<p/>' }, { localVue, pinia })
 
     // must call use after installing the plugin
-    pinia.use(() => {
-      return { pluginN: 20 }
+    pinia.use(({ store }) => {
+      if (!('pluginN' in store.$state)) {
+        // the check above makes this impossible
+        // but in practice we need this until effectScope is released
+        set(store.$state, 'pluginN', ref(20))
+      }
+      set(store, 'pluginN', toRef(store.$state, 'pluginN'))
     })
 
     const store = useStore()