testing-library/svelte-testing-library

Test server-rendered components

Closed this issue · 2 comments

Is it possible today to test a server-rendered component? My understanding is render will return a mounted component with all initial JS ran (top-level <script>, effects and use: actions).

If not, it would be helpful to be able to test a server-rendered component easily; maybe as part of render results: https://testing-library.com/docs/svelte-testing-library/api/#render-results

mcous commented

At the moment, this library is very much concerned with testing the client-side behavior of components. It's difficult for client rendering and server rendering to co-exist in the same suite/Vitest workspace.

Additionally, most of the utility of this library involves setting up the testing-library queries in a DOM environment and cleaning up said DOM. Without the DOM, this library doesn't add much on top of calling Svelte's mount function.

You may want to explore using svelte/server directly in your tests. I'd be curious to hear how you go with it just in case there is interesting / helpful stuff we could wrap! The Vitest setup for such a thing might be a little involved, so happy to help out as needed

Closing this issue as outside the scope of this library