vue-with-setup
v0.0.7
Published
Small vitest helper function to test vue composables.
Readme
vue-with-setup
A vitest utility to use Vue 3 composables in tests without mounting a component.
Install
npm install vue-with-setup --save-devUsage
Basic Example
import { 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);
});With App Context
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);
},
});
...
});Development
- Install dependencies:
pnpm install- Run the unit tests:
pnpm run test- Build the library:
pnpm run buildLicense
MIT License © 2025 Henrik Wenz
