From: Eduardo San Martin Morote Date: Wed, 17 May 2023 08:52:47 +0000 (+0200) Subject: test: add test utils test X-Git-Tag: @pinia/nuxt@0.4.11~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f28b8fb7f8fa183cce2b94a8fe870fb7dec661e5;p=thirdparty%2Fvuejs%2Fpinia.git test: add test utils test --- diff --git a/packages/pinia/__tests__/storeSetup.spec.ts b/packages/pinia/__tests__/storeSetup.spec.ts index aca2ab7d..60385721 100644 --- a/packages/pinia/__tests__/storeSetup.spec.ts +++ b/packages/pinia/__tests__/storeSetup.spec.ts @@ -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(_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: '
{{ injected }}
', + setup() { + const store = useStore() + return { injected: store.injected } + }, + } + const Component = { + template: '', + components: { NestedComponent }, + setup() { + // provide('hello', 'component') + return {} + }, + } + const wrapper = mount(Component, { + global: { + plugins: [pinia], + provide: { + hello: 'pinia', + }, + }, + }) + expect(wrapper.text()).toBe('pinia') + }) })