[READ-ONLY] Mirror of https://github.com/danielroe/nuxt-vitest. An vitest environment with support for testing code that needs a Nuxt runtime environment
nuxt nuxt-module testing unit-testing vitest
0

Configure Feed

Select the types of activity you want to include in your feed.

docs: add documentation for `mountSuspended` (#227)

authored by

邓超 and committed by
GitHub
(Jun 20, 2023, 5:12 PM +0100) ee727dbb 1d96609a

+49 -1
+22 -1
README.md
··· 109 109 110 110 ### `mountSuspended` 111 111 112 - // TODO: 112 + `mountSuspended` allows you to mount any vue component within the Nuxt environment, allowing async setup and access to injections from your Nuxt plugins. For example: 113 + 114 + ```ts 115 + // tests/components/SomeComponents.nuxt.spec.ts 116 + it('can mount some component', async () => { 117 + const component = await mountSuspended(SomeComponent) 118 + expect(component.text()).toMatchInlineSnapshot( 119 + 'This is an auto-imported component' 120 + ) 121 + }) 122 + 123 + // tests/App.nuxt.spec.ts 124 + it('can also mount an app', async () => { 125 + const component = await mountSuspended(App, { route: '/test' }) 126 + expect(component.html()).toMatchInlineSnapshot(` 127 + "<div>This is an auto-imported component</div> 128 + <div> I am a global component </div> 129 + <div>/</div> 130 + <a href=\\"/test\\"> Test link </a>" 131 + `) 132 + }) 133 + ``` 113 134 114 135 ### `mockNuxtImport` 115 136
+27
packages/vitest-environment-nuxt/src/runtime/mount.ts
··· 13 13 route?: RouteLocationRaw 14 14 } 15 15 16 + /** 17 + * `mountSuspended` allows you to mount any vue component within the Nuxt environment, allowing async setup and access to injections from your Nuxt plugins. For example: 18 + * 19 + * ```ts 20 + * // tests/components/SomeComponents.nuxt.spec.ts 21 + * it('can mount some component', async () => { 22 + * const component = await mountSuspended(SomeComponent) 23 + * expect(component.text()).toMatchInlineSnapshot( 24 + * 'This is an auto-imported component' 25 + * ) 26 + * }) 27 + * 28 + * // tests/App.nuxt.spec.ts 29 + * it('can also mount an app', async () => { 30 + * const component = await mountSuspended(App, { route: '/test' }) 31 + * expect(component.html()).toMatchInlineSnapshot(` 32 + * "<div>This is an auto-imported component</div> 33 + * <div> I am a global component </div> 34 + * <div>/</div> 35 + * <a href=\\"/test\\"> Test link </a>" 36 + * `) 37 + * }) 38 + * ``` 39 + * 40 + * @param component the component to be tested 41 + * @param options optional options to set up your component 42 + */ 16 43 export async function mountSuspended<T>( 17 44 component: T, 18 45 options?: MountSuspendedOptions<T>