New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add renderToString function #1971
Conversation
✅ Deploy Preview for vue-test-utils-docs ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
9af6455
to
c8f7180
Compare
@lmiller1990 @freazlike This is a rebased/tidied up version of #1572 |
I forgot to mention I added types tests and a bit of documentation |
c8f7180
to
c8fe9b9
Compare
It is now possible to use `renderToString` to test the SSR rendering of a component. To do so, use `renderToString(MyComponent)`. `renderToString` returns a `Promise<string>` with the HTML rendered. ```ts it('returns correct html with pre-fetched data on server', async () => { const Component = defineComponent({ template: '<div>{{ text }}</div>', setup() { const text = ref<string | null>(null) onServerPrefetch(async () => { text.value = await fakeFetch('onServerPrefetch') }) return { text } } }) const contents = await renderToString(Component) expect(contents).toBe('<div>onServerPrefetch</div>') }) ```
c8fe9b9
to
71bdb19
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good and I think it's a good starting point. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's ship it and start to get feedback! Thanks @cexbrayat and @wobsoriano
It is now possible to use
renderToString
to test the SSR rendering of a component.To do so, use
renderToString(MyComponent)
.renderToString
returns aPromise<string>
with the HTML rendered.