]> 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 10:40:55 +0000 (12:40 +0200)
__tests__/storePlugins.spec.ts

index cc5d17a1935070fe7c0741ddfe2225a1b77447b0..a6d7b8b00a3b0ceeca6e4ec9933212bffb5e13df 100644 (file)
@@ -1,6 +1,6 @@
 import { createPinia, defineStore } from '../src'
 import { mount } from '@vue/test-utils'
-import { App } from 'vue'
+import { App, ref, toRef } from 'vue'
 
 declare module '../src' {
   export interface PiniaCustomProperties<Id> {
@@ -11,6 +11,11 @@ declare module '../src' {
     globalA: string
     globalB: string
   }
+
+  export interface PiniaCustomStateProperties<S> {
+    // pluginN: 'test' extends Id ? number : never | undefined
+    pluginN: number
+  }
 }
 
 describe('store plugins', () => {
@@ -34,8 +39,15 @@ describe('store plugins', () => {
     mount({ template: 'none' }, { global: { plugins: [pinia] } })
 
     // must call use after installing the plugin
-    pinia.use(({ app }) => {
-      return { pluginN: 20, uid: app._uid }
+    pinia.use(({ app, store }) => {
+      if (!('pluginN' in store.$state)) {
+        // @ts-expect-error: the check above makes this impossible
+        // but in practice we need this until effectScope is released
+        store.$state.pluginN = ref(20)
+      }
+      // @ts-expect-error: TODO: allow setting refs
+      store.pluginN = toRef(store.$state, 'pluginN')
+      return { uid: app._uid }
     })
 
     const store = useStore(pinia)