4 ms·
How's unit testing in Svelte today? That's the main worry I have with template-based systems (well, that and TypeScript support, but I hear that that's quite OK
by Vinnl 6y ago
How's unit testing in Svelte today? That's the main worry I have with template-based systems (well, that and TypeScript support, but I hear that that's quite OK now).
- dfrsol 6y agoIt's still the glaring hole in the ecosystem.
- dceddia 6y agoThere’s svelte-testing-library [0] which follows the same approach as the React flavor. It emphasizes testing the app “as the user would use it”, which boils down to rendering components and inspecting the DOM. They intentionally don’t give you visibility into the internal state of the component, which can be weird to get used to if you’re used to doing things like “click the button; assert that state isClicked became true”, but it tends to result in less brittle tests. 0: https://testing-library.com/docs/svelte-testing-library/intro/ https://testing-library.com/docs/svelte-testing-library/intr...
- Vinnl 6y agoThanks, that looks pretty good, and testing-library is excellent. I couldn't find it in the docs, but do you know how this "renders" the Svelte components - in memory using e.g. jsdom, or by firing up a full-fledged browser? (The former would be highly preferable.)
- craigc 6y agoShameless self promotion, but my testing library, Luna, supports testing Svelte components out of the box. https://craig.is/testing/code https://craig.is/testing/code Full documentation on Github: https://github.com/ccampbell/luna-testing https://github.com/ccampbell/luna-testing
- xrd 6y agoIt's not great as other people have mentioned. But I think storybook is a good middle ground for testing (it might be a stretch for others to see it that way) and Svelte has awesome support for storybook.
- Vinnl 6y agoStorybook is neat, and very useful for automated smoke tests, but I wouldn't want to write extensive unit tests that rely on firing up an entire browser - far too flaky to my liking.