Skip to main content
Bun’s Plugin API lets you add custom loaders to your project. The test.preload option in bunfig.toml lets you configure your loader to start before your tests run. Firstly, 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 to tell Bun to preload the plugin, so it loads 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, and it will load the Svelte component as a JavaScript module.
hello-svelte.test.ts

Use bun test to run your tests.
terminal