Skip to main content
Version: Next

wasp/test

The helper for configuring Vitest to test your client code. The helpers you use inside your tests are in wasp/client/test.

Type Aliases​

TestConfig​

TestConfig = NonNullable<ViteUserConfig["test"]>

The test options of your Vitest config, which waspTestConfig takes and returns.

Functions​

waspTestConfig()​

waspTestConfig(options?): InlineConfig

Returns the Vitest options for the test section of your vite.config.ts, with the defaults a Wasp app needs:

  • environment: "jsdom", a simulated browser, so your components can render.
  • include: the test files in your src folder (e.g. TaskList.test.tsx or helpers.spec.js).
  • env: a placeholder REACT_APP_API_URL, since your tests mock the server instead of running it.

Parameters​

options?​

InlineConfig

Vitest options. They override the defaults, except env: Wasp merges it with the default env, and your variables take precedence.

Returns​

InlineConfig

Example​

import { defineConfig } from "vitest/config";
import { wasp } from "wasp/client/vite";
import { waspTestConfig } from "wasp/test";

export default defineConfig({
plugins: [wasp()],
test: waspTestConfig({
setupFiles: ["./src/test/setup.ts"],
}),
});

See​

Testing