Skip to content

Commit

Permalink
Update svelte-test.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed Dec 19, 2024
1 parent e21050d commit d9b2396
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions docs/guides/test/svelte-test.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
---
name: "Test Svelte components with bun:test"
description: "import & require .svelte files in your tests in bun's jest-compatible test api, bun:test"
name: "import, require, and test Svelte components with bun:test"
---

Bun's [Plugin API](/docs/runtime/plugins) lets you add custom loaders to your project and the `test.preload` option in `bunfig.toml` lets you ensure your loaders start before your tests run.

To support tests that import or require `*.svelte` files

Save the following plugin in your project:
To get started, save this plugin in your project.

```ts#svelte-loader.js
// TODO: make this an npm package instead of a file
Expand Down Expand Up @@ -35,16 +32,20 @@ plugin({

---

Add it as a `test.preload` in `bunfig.toml`:
Add this to `bunfig.toml` to tell Bun to preload the plugin, so it loads before your tests run.

```toml
```toml#bunfig.toml
[test]
# Tell Bun to load this plugin before your tests run
preload = ["./svelte-loader.js"]

# This also works:
# test.preload = ["./svelte-loader.js"]
```

---

Write a test that imports or requires a `*.svelte` file:
Now you can `import` or `require` `*.svelte` files in your tests, and it will load the Svelte component as a JavaScript module.

```ts#hello-svelte.test.ts
import { test, expect } from "bun:test";
Expand All @@ -57,7 +58,7 @@ test("svelte", () => {

---

Run your tests:
To run your tests:

```bash
$ bun test
Expand Down

0 comments on commit d9b2396

Please sign in to comment.