Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/1162/stub-recursive-component
# Conflicts: # src/mount.ts
- Loading branch information
Showing
12 changed files
with
921 additions
and
544 deletions.
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
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,42 @@ | ||
# Testing Server-side Rendering | ||
|
||
Vue Test Utils provides `renderToString` to test Vue applications that use server-side rendering (SSR). | ||
This guide will walk you through the process of testing a Vue application that uses SSR. | ||
|
||
## `renderToString` | ||
|
||
`renderToString` is a function that renders a Vue component to a string. | ||
It is an asynchronous function that returns a Promise, | ||
and accepts the same parameters as `mount` or `shallowMount`. | ||
|
||
Let's consider a simple component that uses the `onServerPrefetch` hook: | ||
|
||
```ts | ||
function fakeFetch(text: string) { | ||
return Promise.resolve(text) | ||
} | ||
|
||
const Component = defineComponent({ | ||
template: '<div>{{ text }}</div>', | ||
setup() { | ||
const text = ref<string | null>(null) | ||
|
||
onServerPrefetch(async () => { | ||
text.value = await fakeFetch('onServerPrefetch') | ||
}) | ||
|
||
return { text } | ||
} | ||
}) | ||
``` | ||
|
||
You can write a test for this component using `renderToString`: | ||
|
||
```ts | ||
import { renderToString } from '@vue/test-utils' | ||
|
||
it('renders the value returned by onServerPrefetch', async () => { | ||
const contents = await renderToString(Component) | ||
expect(contents).toBe('<div>onServerPrefetch</div>') | ||
}) | ||
``` |
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
Oops, something went wrong.