From ea9e08ab68604a5a825f3c5bc1cedc411ec1ff78 Mon Sep 17 00:00:00 2001 From: Daniel Sidhion Date: Sat, 9 Nov 2024 23:08:53 -0800 Subject: [PATCH] Clarify how to run unit tests in a browser-like environment --- documentation/docs/07-misc/02-testing.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/documentation/docs/07-misc/02-testing.md b/documentation/docs/07-misc/02-testing.md index 1c3d4ba6e1ef..0b3d7245c8f8 100644 --- a/documentation/docs/07-misc/02-testing.md +++ b/documentation/docs/07-misc/02-testing.md @@ -23,6 +23,10 @@ import { defineConfig } from +++'vitest/config'+++; export default defineConfig({ // ... + // Tell Vitest to run in a browser-like environment to allow some runes to function as if they were running in the browser + test: { + environment: 'jsdom' + }, // Tell Vitest to use the `browser` entry points in `package.json` files, even though it's running in Node resolve: process.env.VITEST ? { @@ -105,6 +109,8 @@ test('Effect', () => { }); ``` +> [!NOTE] `$effect.root` is ignored in a backend testing environment. If your `vite.config.js` or `vitest.config.ts` do not specify a browser-like environment, the code in the test defined above will not run, and the test will misleadingly report that it was successful (because there was no code to run). + ### Component testing It is possible to test your components in isolation using Vitest.