]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
test: add test utils test
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 17 May 2023 08:52:47 +0000 (10:52 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 17 May 2023 08:52:47 +0000 (10:52 +0200)
packages/pinia/__tests__/storeSetup.spec.ts

index aca2ab7d488cf58dfcdfdc3024cdadd2dfa61a32..60385721aaf2764338cc988fbaef1d1c45f31c32 100644 (file)
@@ -1,6 +1,16 @@
 import { beforeEach, describe, it, expect, vi } from 'vitest'
 import { createPinia, defineStore, setActivePinia } from '../src'
-import { computed, createApp, inject, nextTick, ref, watch } from 'vue'
+import {
+  App,
+  computed,
+  createApp,
+  inject,
+  nextTick,
+  provide,
+  ref,
+  watch,
+} from 'vue'
+import { mount } from '@vue/test-utils'
 
 function expectType<T>(_value: T): void {}
 
@@ -146,4 +156,39 @@ describe('store with setup syntax', () => {
     const store = useStore()
     expect(store.injected).toBe('pinia')
   })
+
+  // TODO: until https://github.com/vuejs/test-utils/issues/2059 is fixed
+  it.skip('injects level app injections even within components', async () => {
+    const pinia = createPinia()
+    const useStore = defineStore('id', () => {
+      const injected = ref(inject('hello', 'nope'))
+
+      return { injected }
+    })
+
+    const NestedComponent = {
+      template: '<div>{{ injected }}</div>',
+      setup() {
+        const store = useStore()
+        return { injected: store.injected }
+      },
+    }
+    const Component = {
+      template: '<NestedComponent />',
+      components: { NestedComponent },
+      setup() {
+        // provide('hello', 'component')
+        return {}
+      },
+    }
+    const wrapper = mount(Component, {
+      global: {
+        plugins: [pinia],
+        provide: {
+          hello: 'pinia',
+        },
+      },
+    })
+    expect(wrapper.text()).toBe('pinia')
+  })
 })