docs: note browser condition earlier (#14096)

* docs: note browser condition earlier

The browser condition is also necessary to test runes, so it makes sense to add it to the first occurence to the vite config. Also add a note about more fine-grained alias conditions.

Closes #13961

* Update documentation/docs/07-misc/02-testing.md

---------

Co-authored-by: Rich Harris <rich.harris@vercel.com>
pull/14106/head
Simon H 4 days ago committed by GitHub
parent 9883e7078c
commit aac4cbd1f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -21,9 +21,18 @@ Then adjust your `vite.config.js`:
/// file: vite.config.js
import { defineConfig } from +++'vitest/config'+++;
export default defineConfig({ /* ... */ })
export default defineConfig({
// ...
// Tell Vitest to use the `browser` entry points in `package.json` files, even though it's running in Node
resolve: process.env.VITEST
? {
conditions: ['browser']
}
: undefined
```
> [!NOTE] If loading the browser version of all your packages is undesirable, because (for example) you also test backend libraries, [you may need to resort to an alias configuration](https://github.com/testing-library/svelte-testing-library/issues/222#issuecomment-1909993331)
You can now write unit tests for code inside your `.js/.ts` files:
```js

Loading…
Cancel
Save