Skip to content
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

Merged
merged 1 commit into from Feb 19, 2023
Merged

Commits on Feb 10, 2023

  1. feat: add renderToString function

    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>')
      })
    ```
    wobsoriano authored and cexbrayat committed Feb 10, 2023
    Copy the full SHA
    71bdb19 View commit details
    Browse the repository at this point in the history