]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
chore: add playground tests
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 17 May 2023 08:40:13 +0000 (10:40 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 17 May 2023 08:40:13 +0000 (10:40 +0200)
packages/playground/src/App.vue
packages/playground/src/main.ts
packages/playground/src/stores/counterSetup.ts
packages/playground/src/views/CounterSetupStore.vue

index 3f0e3f8c9f69ad9ecb859c7363aeefcbabc08d7f..28712067440d89518623a4722ef088a27522e155 100644 (file)
 </template>
 
 <script lang="ts" setup>
-import { computed } from 'vue'
+import { computed, provide } from 'vue'
 import { useRoute, useRouter } from 'vue-router'
 
 const router = useRouter()
 const route = useRoute()
 
+provide('hello', 'from component')
+
 const pages = router
   .getRoutes()
   .filter((route) => !route.meta.hide)
index bae664bcac50bdc52ad6da269007b334016ee9a5..2d9209d86d9852265dec327b2d2539210893bbf5 100644 (file)
@@ -60,6 +60,10 @@ if (import.meta.hot) {
   //   }
 }
 
-const app = createApp(App).use(pinia).use(router)
+const app = createApp(App)
+  .use(pinia)
+  .use(router)
+  // used in counter setup for tests
+  .provide('injected', 'global')
 
 app.mount('#app')
index 4c5330da2336a4aa16b874968a7b3af97839dff6..99e36aad425c386a3cf2cac440ca88ea64047e1a 100644 (file)
@@ -1,4 +1,4 @@
-import { computed, toRefs, reactive } from 'vue'
+import { computed, toRefs, reactive, inject } from 'vue'
 import { acceptHMRUpdate, defineStore } from 'pinia'
 
 const delay = (t: number) => new Promise((r) => setTimeout(r, t))
@@ -11,6 +11,9 @@ export const useCounter = defineStore('counter-setup', () => {
     numbers: [] as number[],
   })
 
+  const injected = inject('injected', 'fallback value')
+  console.log('injected (should be global)', injected)
+
   const double = computed(() => state.n * 2)
 
   function increment(amount = 1) {
index c06656b65923647de6976cd7933e9be24533bd68..5f2b7c2380b4d5ba243dd028c70fd3d91b9d94bb 100644 (file)
@@ -1,3 +1,21 @@
+<script lang="ts" setup>
+import { ref, inject } from 'vue'
+import { useCounter } from '../stores/counterSetup'
+
+console.log(
+  '(1) injected (within component should be from component)',
+  inject('hello')
+)
+
+const counter = useCounter()
+
+console.log(
+  '(2) injected (within component should be from component)',
+  inject('hello')
+)
+const n = ref(0)
+</script>
+
 <template>
   <h2>Local variables</h2>
 
 
   <pre>{{ counter.$state }}</pre>
 </template>
-
-<script lang="ts" setup>
-import { ref } from 'vue'
-import { useCounter } from '../stores/counterSetup'
-
-const counter = useCounter()
-const n = ref(0)
-</script>