Skip to main content
Use Bun’s Plugin API to add a custom loader for .svelte files, and the test.preload option in bunfig.toml to load it before your tests run. First, install @testing-library/svelte, svelte, and @happy-dom/global-registrator.
terminal
Then, save this plugin in your project.
svelte-loader.ts

Add this to bunfig.toml so Bun preloads the plugin before your tests run.
bunfig.toml

Add an example .svelte file in your project.
Counter.svelte

Now you can import or require *.svelte files in your tests. Bun loads each Svelte component as a JavaScript module.
hello-svelte.test.ts

Use bun test to run your tests.
terminal