A vitest utility to use Vue 3 composables in tests without mounting a component.
npm install vue-with-setup --save-devimport { expect, test } from "vitest";
import { withSetup } from "vue-with-setup";
import { useToggle } from "@vueuse/core";
test("useToggle", () => {
const [[value, toggle]] = withSetup(() => useToggle());
expect(value.value).toBe(false);
toggle();
expect(value.value).toBe(true);
toggle();
expect(value.value).toBe(false);
});import { expect, test } from "vitest";
import { withSetup } from "vue-with-setup";
test("useToggle", () => {
const [result, app] = withSetup(() => useMyComposable(), {
configureApp(app) {
// provide app context here
app.use(SomePlugin);
},
});
...
});- Install dependencies:
pnpm install- Run the unit tests:
pnpm run test- Build the library:
pnpm run buildMIT License © 2025 Henrik Wenz