-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add example test for nuxt-injected value (#663)
Co-authored-by: Oskar Olsson <oskar.olsson@backmarket.com>
- Loading branch information
Showing
4 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
examples/app-vitest-full/components/InjectedValueComponent.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) |
12 changes: 12 additions & 0 deletions
12
examples/app-vitest-full/tests/nuxt/injected-value-component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) |