Skip to content

HaNdTriX/vue-with-setup

Repository files navigation

vue-with-setup

NPM version

A vitest utility to use Vue 3 composables in tests without mounting a component.

Install

npm install vue-with-setup --save-dev

Usage

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 build

License

MIT License © 2025 Henrik Wenz