Skip to content

Commit

Permalink
test: add example test for nuxt-injected value
Browse files Browse the repository at this point in the history
resolves #539

Co-authored-by: Oskar Olsson <oskar.olsson@backmarket.com>
  • Loading branch information
danielroe and oskarols committed Dec 19, 2023
1 parent 269df28 commit fb6f3be
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
11 changes: 11 additions & 0 deletions examples/app-vitest-full/components/InjectedValueComponent.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<template>
<div>
{{ value }}
</div>
</template>

<script setup lang="ts">
import { CUSTOM_VUE_PLUGIN_SYMBOL } from '../plugins/inject-value'
const value = inject(CUSTOM_VUE_PLUGIN_SYMBOL)
</script>
13 changes: 13 additions & 0 deletions examples/app-vitest-full/plugins/inject-value.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const CUSTOM_VUE_PLUGIN_SYMBOL = Symbol('CUSTOM_VUE_PLUGIN_INJECTED')

export const VUE_INJECTED_VALUE = 'injected vue plugin value'

export default defineNuxtPlugin((nuxtApp) => {
const vuePlugin = {
install(app: any) {
app.provide(CUSTOM_VUE_PLUGIN_SYMBOL, VUE_INJECTED_VALUE)
},
}

nuxtApp.vueApp.use(vuePlugin)
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { describe, expect, it } from 'vitest'
import { mountSuspended } from '@nuxt/test-utils/runtime'

import { VUE_INJECTED_VALUE } from '~/plugins/inject-value'
import InjectedValueComponent from '~/components/InjectedValueComponent.vue'

describe('InjectedValueComponent', () => {
it('can use injected values from a plugin', async () => {
const component = await mountSuspended(InjectedValueComponent)
expect(component.text()).toContain(VUE_INJECTED_VALUE)
})
})

0 comments on commit fb6f3be

Please sign in to comment.