An open API service indexing awesome lists of open source software.

https://github.com/pokujs/vue

A Poku plugin for Vue component testing with DOM adapters.
https://github.com/pokujs/vue

Last synced: 2 months ago
JSON representation

A Poku plugin for Vue component testing with DOM adapters.

Awesome Lists containing this project

README

          


Poku's Logo

# @pokujs/vue

Enjoying **Poku**? [Give him a star to show your support](https://github.com/wellwelwel/poku) ๐ŸŒŸ

---

๐Ÿ“˜ [**Documentation**](https://github.com/pokujs/vue#readme)

---

๐Ÿงช [**@pokujs/vue**](https://github.com/pokujs/vue) is a **Poku** plugin for Vue component testing with DOM adapters.

> [!TIP]
>
> Render Vue components in isolated test files โ€” automatic TSX loader injection, DOM environment setup, and optional render metrics included.

---

## Quickstart

### Install

```bash
# Node.js
npm i -D @pokujs/vue
```

```bash
# Bun
bun add -d @pokujs/vue
```

```bash
# Deno (optional)
deno add npm:@pokujs/vue
```

Install a DOM adapter (at least one is required):

```bash
# happy-dom (recommended)
npm i -D happy-dom \
@happy-dom/global-registrator
```

```bash
# jsdom
npm i -D jsdom
```

### Enable the Plugin

```js
// poku.config.js
import { defineConfig } from 'poku';
import { vueTestingPlugin } from '@pokujs/vue/plugin';

export default defineConfig({
plugins: [
vueTestingPlugin({
dom: 'happy-dom',
}),
],
});
```

### Write Tests

```tsx
// tests/my-component.test.tsx
import { afterEach, assert, test } from 'poku';
import { cleanup, render, screen } from '@pokujs/vue';

afterEach(cleanup);

test('renders a heading', () => {
render(

Hello

);
assert.strictEqual(screen.getByRole('heading').textContent, 'Hello');
});
```

---

## Compatibility

### Runtime ร— DOM Adapter

| | Node.js โ‰ฅ 20 | Bun โ‰ฅ 1 | Deno โ‰ฅ 2 |
| ---------------- | :----------: | :-----: | :------: |
| **happy-dom** | โœ… | โœ… | โœ… |
| **jsdom** | โœ… | โœ… | โš ๏ธ |
| **custom setup** | โœ… | โœ… | โœ… |

> [!NOTE]
>
> `jsdom` under Deno may be unstable depending on Deno's npm compatibility layer for the current `jsdom` version. For Deno projects, prefer `happy-dom`.

---

## Options

```ts
vueTestingPlugin({
/**
* DOM adapter to use. Defaults to 'happy-dom'.
* - 'happy-dom' โ€” fast, recommended for most tests
* - 'jsdom' โ€” broader browser API coverage
* - { setupModule } โ€” path to a custom DOM setup module
*/
dom: 'happy-dom',

/** Base URL assigned to the DOM environment. */
domUrl: 'http://localhost:3000/',

/**
* Render metrics. Disabled by default.
* Pass `true` for defaults, or an object for fine-grained control.
*/
metrics: {
enabled: true,
topN: 5,
minDurationMs: 0,
reporter(summary) {
console.log(summary.topSlowest);
},
},
});
```

---

## License

[MIT](./LICENSE)