svelte-society/sveltesociety.dev

Recipe for using TypeScript and Jest tests at the same time

atuttle opened this issue · 5 comments

There's a recipe for using TypeScript and a recipe for writing tests with Jest, but nothing to get them both running together. I can write components using TS but as soon as I try to test them it all falls apart. I've never used Jest and TS together before, so a recipe would be extremely helpful.

I believe that svelte-add-jest has TypeScript support. Probably the easiest thing to do would be to use it: https://github.com/rossyman/svelte-add-jest

I think that for setting up any integration, Svelte Adders is basically always the easiest way to manage it. Not sure if there's something we should do to make that more discoverable

Interesting, I may have to give that a try.

I did find this and while it's slightly out of date (uses Jest 26 and with v27 requires setting "testEnvironment": "jsdom") it's pretty helpful.

svelte-add-jest uses Jest 27 and also avoids starting a new process for each test, which is only possible with Jest 27

The docs seem to indicate that svelte-add-jest is for SvelteKit specifically. Will it work on vanilla Svelte?

Probably not though perhaps. But I imagine you could see what it changed and then make the same changes in your project