Skip to content

Commit

Permalink
Readme document test runner config to avoid transpiling errors in dow…
Browse files Browse the repository at this point in the history
…nstream testing (#54)

* Add Unit Test & stackblitz link in README (closes #48)

* bit more concise wording

Co-authored-by: Janosh Riebesell <[email protected]>
  • Loading branch information
wd-David and janosh authored Mar 1, 2022
1 parent 33864be commit 256053d
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,40 @@ You can alternatively style every part of this component with more fine-grained
}
```

## Downstream testing

To test a Svelte component which imports `svelte-multiselect`, you need to configure your test runner to avoid [transpiling issues](https://github.com/EmilTholin/svelte-routing/issues/140#issuecomment-661682571).

For Jest, exclude `svelte-multiselect` from `transformIgnorePatterns` in your `jest.config.json`:

```json
{
"transformIgnorePatterns": ["node_modules/?!(svelte-multiselect)"],
"transform": {
"^.+\\.[t|j]s?$": "esbuild-jest",
"^.+\\.svelte$": ["svelte-jester", { "preprocess": true }]
}
}
```

For Vitest, include `svelte-multiselect` in `deps.inline`:

```ts
// vite.config.ts
import { svelte } from '@sveltejs/vite-plugin-svelte'

export default {
plugins: [svelte({ hot: !process.env.VITEST })],
test: {
deps: {
inline: [/svelte-multiselect/],
},
},
}
```

Here's a [Stackblitz example](https://stackblitz.com/fork/github/davipon/test-svelte-multiselect?initialPath=__vitest__) that also uses [`'vitest-svelte-kit'`](https://github.com/nickbreaton/vitest-svelte-kit).

## Want to contribute?

To submit a PR, clone the repo, install dependencies and start the dev server to try out your changes.
Expand Down

0 comments on commit 256053d

Please sign in to comment.