> ## Documentation Index
> Fetch the complete documentation index at: https://docs.quiesco.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# VitestでのDriverパターン

> Vitestのテストに、ビジネスのdriverをフィクスチャーとして渡します。

Vitestでは、[driver](https://docs.quiesco.dev/ja/driver-pattern.md#the-driver)をフィクスチャーにします。テストは`app`の代わりに`todos`を受け取ります。

## フィクスチャー

`@quiesco/vitest`の`test`は、`app`フィクスチャー付きのVitestの`test`です。これをdriverで拡張します。

```ts theme={null}
// e2e/fixtures.ts
import { test as base } from '@quiesco/vitest';

import { type TodoDriver, UiTodoDriver } from './todo-driver';

export { expect } from '@quiesco/vitest';

export const test = base.extend<{ todos: TodoDriver }>({
  todos: async ({ app }, use) => {
    await use(new UiTodoDriver(app));
  },
});
```

`todos`は`app`を使うので、`todos`を受け取るテストも、`app`を受け取るテストと同じく実行前にリセットされます。

## テスト

`test`と`expect`は、`@quiesco/vitest`ではなくフィクスチャーのファイルからインポートします。

```ts theme={null}
// e2e/todos.test.ts
import { expect, test } from './fixtures';

test('a new todo appears at the top of the list', async ({ todos }) => {
  await todos.seed([{ title: 'Call the dentist' }]);
  await todos.addTodo('Buy milk');

  expect(await todos.todoTitles()).toEqual(['Buy milk', 'Call the dentist']);
});
```

テストにテストIDもタップもありません。driverにない操作が必要なテストは、`todos`と一緒に`app`も受け取れます。

Vitestについて詳しくは[Vitest](https://docs.quiesco.dev/ja/vitest.md)を参照してください。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.