News for hackers. Stuff that matters.
Re:Comparing Svelte and React by Vinnl on Wednesday March 24, 2021 @05:52PM (#26573448)
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).
Re:Comparing Svelte and React by dceddia on Wednesday March 24, 2021 @06:45PM (#26573981)
There’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/intr...

Re:Comparing Svelte and React by Vinnl on Thursday March 25, 2021 @03:45AM (#26577407)
Thanks, 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.)
Re:Comparing Svelte and React by dceddia on Thursday March 25, 2021 @08:37AM (#26579451)
Testing-library uses jsdom across the board, as far as I know. It might support running in a full browser too but I haven’t used it that way.

For end-to-end tests with a real browser, Cypress is a good option.

Re:Comparing Svelte and React by Vinnl on Thursday March 25, 2021 @01:01PM (#26582664)
Cool, sounds like it should be in a usable state then.
Re:Comparing Svelte and React by dfrsol on Wednesday March 24, 2021 @05:59PM (#26573535)
It's still the glaring hole in the ecosystem.
Re:Comparing Svelte and React by craigc on Wednesday March 24, 2021 @08:07PM (#26574789)
Shameless self promotion, but my testing library, Luna, supports testing Svelte components out of the box.

https://craig.is/testing/code

Full documentation on Github:

https://github.com/ccampbell/luna-testing

Re:Comparing Svelte and React by xrd on Thursday March 25, 2021 @12:46AM (#26576685)
It'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.
Re:Comparing Svelte and React by Vinnl on Thursday March 25, 2021 @03:50AM (#26577426)
Storybook 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.