Skip to content

Commit

Permalink
test: add example test for nuxt-injected value (#663)
Browse files Browse the repository at this point in the history
Co-authored-by: Oskar Olsson <oskar.olsson@backmarket.com>
  • Loading branch information
danielroe and oskarols authored Dec 19, 2023
1 parent 269df28 commit 7f2d479
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
5 changes: 4 additions & 1 deletion examples/app-vitest-full/components/BoundAttrs.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<template>
<button :type="type" v-bind="attrs" />
<button
:type="type"
v-bind="attrs"
/>
</template>

<script lang="ts">
Expand Down
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 7f2d479

Please sign in to comment.