diff --git a/docs/api/browser/svelte.md b/docs/api/browser/svelte.md index 4ae2c964f..9db5c7071 100644 --- a/docs/api/browser/svelte.md +++ b/docs/api/browser/svelte.md @@ -39,20 +39,11 @@ export function render( Component: ComponentImport, options?: ComponentOptions, renderOptions?: SetupOptions -): RenderResult & PromiseLike> +): Promise> ``` The `render` function records a `svelte.render` trace mark, visible in the [Trace View](/guide/browser/trace-view). -::: warning -Synchronous usage of `render` is deprecated and will be removed in the next major version. Please always `await` the result: - -```ts -const screen = render(Component) // [!code --] -const screen = await render(Component) // [!code ++] -``` -::: - ### Options The `render` function supports either options that you can pass down to [`mount`](https://svelte.dev/docs/svelte/imperative-component-api#mount) or props directly: @@ -174,10 +165,6 @@ function unmount(): Promise Unmount and destroy the Svelte component. Also records a `svelte.unmount` trace mark in the [Trace View](/guide/browser/trace-view). This is useful for testing what happens when your component is removed from the page (like testing that you don't leave event handlers hanging around causing memory leaks). -::: warning -Synchronous usage of `unmount` is deprecated and will be removed in the next major version. Please always `await` the result. -::: - ```ts import { render } from 'vitest-browser-svelte' diff --git a/docs/api/browser/vue.md b/docs/api/browser/vue.md index 4695a47f7..af3b47ac3 100644 --- a/docs/api/browser/vue.md +++ b/docs/api/browser/vue.md @@ -40,20 +40,11 @@ The package exposes two entry points: `vitest-browser-vue` and `vitest-browser-v export function render( component: Component, options?: ComponentRenderOptions, -): RenderResult & PromiseLike +): Promise ``` The `render` function records a `vue.render` trace mark, visible in the [Trace View](/guide/browser/trace-view). -::: warning -Synchronous usage of `render` is deprecated and will be removed in the next major version. Please always `await` the result: - -```ts -const screen = render(Component) // [!code --] -const screen = await render(Component) // [!code ++] -``` -::: - ### Options The `render` function supports all [`mount` options](https://test-utils.vuejs.org/api/#mount) from `@vue/test-utils` (except `attachTo` - use `container` instead). In addition to them, there are also `container` and `baseElement`. @@ -136,17 +127,13 @@ This method is a shortcut for `console.log(prettyDOM(baseElement))`. It will pri #### rerender ```ts -function rerender(props: Partial): void & PromiseLike +function rerender(props: Partial): Promise ``` Also records a `vue.rerender` trace mark in the [Trace View](/guide/browser/trace-view). It is better if you test the component that's doing the prop updating to ensure that the props are being updated correctly to avoid relying on implementation details in your tests. That said, if you'd prefer to update the props of a rendered component in your test, this function can be used to update props of the rendered component. -::: warning -Synchronous usage of `rerender` is deprecated and will be removed in the next major version. Please always `await` the result. -::: - ```js import { render } from 'vitest-browser-vue' @@ -159,15 +146,11 @@ await rerender({ number: 2 }) #### unmount ```ts -function unmount(): void & PromiseLike +function unmount(): Promise ``` This will cause the rendered component to be unmounted. Also records a `vue.unmount` trace mark in the [Trace View](/guide/browser/trace-view). This is useful for testing what happens when your component is removed from the page (like testing that you don't leave event handlers hanging around causing memory leaks). -::: warning -Synchronous usage of `unmount` is deprecated and will be removed in the next major version. Please always `await` the result. -::: - #### emitted ```ts diff --git a/docs/guide/browser/index.md b/docs/guide/browser/index.md index d13f882c6..7f7fee18d 100644 --- a/docs/guide/browser/index.md +++ b/docs/guide/browser/index.md @@ -432,7 +432,7 @@ import { render } from 'vitest-browser-vue' import Component from './Component.vue' test('properly handles v-model', async () => { - const screen = render(Component) + const screen = await render(Component) // Asserts initial state. await expect.element(screen.getByText('Hi, my name is Alice')).toBeInTheDocument() @@ -454,7 +454,7 @@ import { expect, test } from 'vitest' import Greeter from './greeter.svelte' test('greeting appears on click', async () => { - const screen = render(Greeter, { name: 'World' }) + const screen = await render(Greeter, { name: 'World' }) const button = screen.getByRole('button') await button.click() diff --git a/packages/ui/client/test.ts b/packages/ui/client/test.ts index 13815a19c..a8afda632 100644 --- a/packages/ui/client/test.ts +++ b/packages/ui/client/test.ts @@ -10,13 +10,13 @@ export { page } from 'vitest/browser' export const render = vi.defineHelper(( component: C, options?: ComponentRenderOptions, -): PromiseLike> => { - return _render(component, { +): Promise> => { + return Promise.resolve(_render(component, { ...options, global: { directives: { tooltip: vTooltip, }, }, - }) + })) }) diff --git a/packages/vitest/src/create/browser/examples.ts b/packages/vitest/src/create/browser/examples.ts index 0268eca13..81a9399e1 100644 --- a/packages/vitest/src/create/browser/examples.ts +++ b/packages/vitest/src/create/browser/examples.ts @@ -68,7 +68,7 @@ import { render } from 'vitest-browser-vue' import HelloWorld from './HelloWorld.vue' test('renders name', async () => { - const { getByText } = render(HelloWorld, { + const { getByText } = await render(HelloWorld, { props: { name: 'Vitest' }, }) await expect.element(getByText('Hello Vitest!')).toBeInTheDocument() @@ -98,7 +98,7 @@ import { render } from 'vitest-browser-svelte' import HelloWorld from './HelloWorld.svelte' test('renders name', async () => { - const { getByText } = render(HelloWorld, { name: 'Vitest' }) + const { getByText } = await render(HelloWorld, { name: 'Vitest' }) await expect.element(getByText('Hello Vitest!')).toBeInTheDocument() }) `,