> ## 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.

# アサーション

> 画面の内容を確認する：表示、テキスト、値、ラベル、有効、チェック、フォーカス、props、個数。成り立つまで再試行されます。

アサーションは画面を確認し、成り立つか呼び出しのタイムアウトになるまで**再試行します**（[呼び出しのオプション](https://docs.quiesco.dev/ja/api.md#call-options)を参照）。タイムアウトになると、期待値と実際の値を含む`ASSERTION_FAILED`で失敗します。そのため、テストで確認の前にアプリを待つ必要はありません。

```ts theme={null}
await app.tap('add-todo');
// 新しい行が現れるまで再試行される
await app.expectText({ id: 'todo-title', index: 0 }, 'Buy milk');
```

どのアサーションも、マッチした要素の[概要](https://docs.quiesco.dev/ja/api-queries.md#element-summary)で解決します。1つの要素についてのアサーション（テキスト、値、ラベル、フォーカス、有効、チェック、props）のほとんどは、マッチが**ちょうど1つ**必要です。そうしたアサーションは以下にその旨を書いています。各アサーションには[チェーン形式](#expect)の`app.expect(target).toBe…()`もあります。

## 表示と存在

### `expectVisible(target, options?)`

```ts theme={null}
expectVisible(
  target: MatcherInput,
  options?: VisibleOptions,
): Promise<ElementSummary[]>
```

型： [`MatcherInput`](./api-types#matcherinput) · [`VisibleOptions`](./api-types#visibleoptions) · [`ElementSummary`](./api-types#elementsummary)

マッチする要素が少なくとも1つ[表示されている](https://docs.quiesco.dev/ja/api-matchers.md#visibility)ときに成り立ちます。

```ts theme={null}
await app.expectVisible('todo-list-screen');

// バナーの面積の75%以上が表示されている
await app.expectVisible('promo-banner', { ratio: 0.75 });
```

| オプション | デフォルト | 意味 |
| - | - | - |
| `ratio` | — | (0, 1]の数値。要素の面積のうち少なくともこの割合が表示されている必要がある。範囲外なら`RangeError`をスロー |
| `timeoutMs` | `sync.timeoutMs`（10秒） | アサーションが成立するまで再試行する最大時間 |
| `sync` | `true` | `false`：この呼び出しの前後でアプリのアイドルを待ちません（[共通オプション](https://docs.quiesco.dev/ja/api.md#call-options)） |

### `expectNotVisible(target, options?)`

```ts theme={null}
expectNotVisible(
  target: MatcherInput,
  options?: CallOptions,
): Promise<ElementSummary[]>
```

型： [`MatcherInput`](./api-types#matcherinput) · [`CallOptions`](./api-types#calloptions) · [`ElementSummary`](./api-types#elementsummary)

マッチする要素が1つも表示されていないとき（存在しない、または隠れている）に成り立ちます。

```ts theme={null}
await app.tap('close-dialog');
await app.expectNotVisible('confirm-dialog');
```

| オプション | デフォルト | 意味 |
| - | - | - |
| `timeoutMs` | `sync.timeoutMs`（10秒） | アサーションが成立するまで再試行する最大時間 |
| `sync` | `true` | `false`：この呼び出しの前後でアプリのアイドルを待ちません（[共通オプション](https://docs.quiesco.dev/ja/api.md#call-options)） |

### `expectExists(target, options?)`

```ts theme={null}
expectExists(
  target: MatcherInput,
  options?: CallOptions,
): Promise<ElementSummary[]>
```

型： [`MatcherInput`](./api-types#matcherinput) · [`CallOptions`](./api-types#calloptions) · [`ElementSummary`](./api-types#elementsummary)

表示の有無にかかわらず、マッチする要素が要素ツリーにあるときに成り立ちます。

```ts theme={null}
// リストのさらに下に描画されているが、まだスクロールしていない
await app.expectExists({ id: 'todo-row', index: 49 });
```

| オプション | デフォルト | 意味 |
| - | - | - |
| `timeoutMs` | `sync.timeoutMs`（10秒） | アサーションが成立するまで再試行する最大時間 |
| `sync` | `true` | `false`：この呼び出しの前後でアプリのアイドルを待ちません（[共通オプション](https://docs.quiesco.dev/ja/api.md#call-options)） |

### `expectNotExists(target, options?)`

```ts theme={null}
expectNotExists(
  target: MatcherInput,
  options?: CallOptions,
): Promise<ElementSummary[]>
```

型： [`MatcherInput`](./api-types#matcherinput) · [`CallOptions`](./api-types#calloptions) · [`ElementSummary`](./api-types#elementsummary)

マッチする要素が要素ツリーにないときに成り立ちます。

```ts theme={null}
await app.swipe({ id: 'todo-row', has: { text: 'Buy milk' } }, Direction.left);
await app.tap('delete');
await app.expectNotExists({ text: 'Buy milk' });
```

| オプション | デフォルト | 意味 |
| - | - | - |
| `timeoutMs` | `sync.timeoutMs`（10秒） | アサーションが成立するまで再試行する最大時間 |
| `sync` | `true` | `false`：この呼び出しの前後でアプリのアイドルを待ちません（[共通オプション](https://docs.quiesco.dev/ja/api.md#call-options)） |

### `expectCount(target, n, options?)`

```ts theme={null}
expectCount(
  target: MatcherInput,
  n: number,
  options?: CallOptions,
): Promise<ElementSummary[]>
```

型： [`MatcherInput`](./api-types#matcherinput) · [`CallOptions`](./api-types#calloptions) · [`ElementSummary`](./api-types#elementsummary)

マッチする要素がちょうど`n`個のときに成り立ちます。

```ts theme={null}
await app.type('new-todo', 'Walk the dog');
await app.pressKey('new-todo', KeyName.enter);
await app.expectCount({ id: 'todo-row' }, 3);
```

| オプション | デフォルト | 意味 |
| - | - | - |
| `timeoutMs` | `sync.timeoutMs`（10秒） | アサーションが成立するまで再試行する最大時間 |
| `sync` | `true` | `false`：この呼び出しの前後でアプリのアイドルを待ちません（[共通オプション](https://docs.quiesco.dev/ja/api.md#call-options)） |

## 内容

### `expectText(target, text, options?)`

```ts theme={null}
expectText(
  target: MatcherInput,
  text: TextQuery,
  options?: CallOptions,
): Promise<ElementSummary[]>
```

型： [`MatcherInput`](./api-types#matcherinput) · [`TextQuery`](./api-types#textquery) · [`CallOptions`](./api-types#calloptions) · [`ElementSummary`](./api-types#elementsummary)

マッチがちょうど1つで、そのテキストが`text`と等しい（`text`が正規表現ならマッチする）ときに成り立ちます。

```ts theme={null}
await app.expectText('todo-title', 'Buy milk');

await app.expectText('items-left', /^\d+ items? left$/);
```

| オプション | デフォルト | 意味 |
| - | - | - |
| `timeoutMs` | `sync.timeoutMs`（10秒） | アサーションが成立するまで再試行する最大時間 |
| `sync` | `true` | `false`：この呼び出しの前後でアプリのアイドルを待ちません（[共通オプション](https://docs.quiesco.dev/ja/api.md#call-options)） |

### `expectValue(target, value, options?)`

```ts theme={null}
expectValue(
  target: MatcherInput,
  value: JsonValue | RegExp | Date,
  options?: CallOptions,
): Promise<ElementSummary[]>
```

型： [`MatcherInput`](./api-types#matcherinput) · [`JsonValue`](./api-types#jsonvalue) · [`CallOptions`](./api-types#calloptions) · [`ElementSummary`](./api-types#elementsummary)

マッチがちょうど1つで、その値が`value`と等しい（`value`が正規表現ならマッチする）ときに成り立ちます。値とは、入力欄のテキスト、スイッチの状態、スライダーやピッカーの値、または`accessibilityValue`です。

```ts theme={null}
await app.expectValue('email', 'ann@example.com');
await app.expectValue('dark-mode-switch', true);
await app.expectValue('volume-slider', 0.5);

// 日付ピッカー：表示内容をデバイスのローカル時刻で比較する
await app.expectValue('due-date', new Date(2031, 11, 24));
```

| オプション | デフォルト | 意味 |
| - | - | - |
| `timeoutMs` | `sync.timeoutMs`（10秒） | アサーションが成立するまで再試行する最大時間 |
| `sync` | `true` | `false`：この呼び出しの前後でアプリのアイドルを待ちません（[共通オプション](https://docs.quiesco.dev/ja/api.md#call-options)） |

日付・時刻ピッカーの値は、表示されている内容をデバイスのローカル時刻で表したものです：`"2031-12-24"`（モード`date`）、`"20:15"`（`time`）、`"2031-12-24T20:15"`（`datetime`）。秒が0でなければ秒も付きます。`Date`は、これらの部分が一致すればマッチします。[日付・時刻ピッカー](https://docs.quiesco.dev/ja/api-value-controls.md#date-and-time-pickers)を参照してください。

### `expectLabel(target, text, options?)`

```ts theme={null}
expectLabel(
  target: MatcherInput,
  text: TextQuery,
  options?: CallOptions,
): Promise<ElementSummary[]>
```

型： [`MatcherInput`](./api-types#matcherinput) · [`TextQuery`](./api-types#textquery) · [`CallOptions`](./api-types#calloptions) · [`ElementSummary`](./api-types#elementsummary)

マッチがちょうど1つで、そのアクセシビリティラベルが`text`と等しい（`text`が正規表現ならマッチする）ときに成り立ちます。

```ts theme={null}
await app.expectLabel('cart-button', 'Cart, 3 items');

await app.expectLabel('cart-button', /^Cart, \d+ items$/);
```

| オプション | デフォルト | 意味 |
| - | - | - |
| `timeoutMs` | `sync.timeoutMs`（10秒） | アサーションが成立するまで再試行する最大時間 |
| `sync` | `true` | `false`：この呼び出しの前後でアプリのアイドルを待ちません（[共通オプション](https://docs.quiesco.dev/ja/api.md#call-options)） |

### `expectProp(target, prop, value, options?)`

```ts theme={null}
expectProp(
  target: MatcherInput,
  prop: string,
  value: JsonValue,
  options?: CallOptions,
): Promise<ElementSummary[]>
```

型： [`MatcherInput`](./api-types#matcherinput) · [`JsonValue`](./api-types#jsonvalue) · [`CallOptions`](./api-types#calloptions) · [`ElementSummary`](./api-types#elementsummary)

マッチがちょうど1つで、`prop`で指定したpropがこのJSON値を持つときに成り立ちます。まずホスト要素のprops、次にそのコンポーネントのpropsを調べます（例：`disabled`、`value`）。

```ts theme={null}
await app.expectProp('new-todo', 'placeholder', 'What needs to be done?');

await app.expectProp('save', 'disabled', false);
```

| オプション | デフォルト | 意味 |
| - | - | - |
| `timeoutMs` | `sync.timeoutMs`（10秒） | アサーションが成立するまで再試行する最大時間 |
| `sync` | `true` | `false`：この呼び出しの前後でアプリのアイドルを待ちません（[共通オプション](https://docs.quiesco.dev/ja/api.md#call-options)） |

## 状態

### `expectEnabled(target, options?)`

```ts theme={null}
expectEnabled(
  target: MatcherInput,
  options?: CallOptions,
): Promise<ElementSummary[]>
```

型： [`MatcherInput`](./api-types#matcherinput) · [`CallOptions`](./api-types#calloptions) · [`ElementSummary`](./api-types#elementsummary)

マッチがちょうど1つで、それが有効なときに成り立ちます。

```ts theme={null}
await app.type('email', 'ann@example.com');
await app.type('password', 'secret');
await app.expectEnabled('sign-in');
```

| オプション | デフォルト | 意味 |
| - | - | - |
| `timeoutMs` | `sync.timeoutMs`（10秒） | アサーションが成立するまで再試行する最大時間 |
| `sync` | `true` | `false`：この呼び出しの前後でアプリのアイドルを待ちません（[共通オプション](https://docs.quiesco.dev/ja/api.md#call-options)） |

### `expectDisabled(target, options?)`

```ts theme={null}
expectDisabled(
  target: MatcherInput,
  options?: CallOptions,
): Promise<ElementSummary[]>
```

型： [`MatcherInput`](./api-types#matcherinput) · [`CallOptions`](./api-types#calloptions) · [`ElementSummary`](./api-types#elementsummary)

マッチがちょうど1つで、それが無効なときに成り立ちます。

```ts theme={null}
// フォームが空
await app.expectDisabled('sign-in');
```

| オプション | デフォルト | 意味 |
| - | - | - |
| `timeoutMs` | `sync.timeoutMs`（10秒） | アサーションが成立するまで再試行する最大時間 |
| `sync` | `true` | `false`：この呼び出しの前後でアプリのアイドルを待ちません（[共通オプション](https://docs.quiesco.dev/ja/api.md#call-options)） |

要素は`disabled`、`accessibilityState.disabled`、`aria-disabled`、`editable={false}`によって無効になります。祖先から継承した場合も含みます。

### `expectChecked(target, options?)`

```ts theme={null}
expectChecked(
  target: MatcherInput,
  options?: CallOptions,
): Promise<ElementSummary[]>
```

型： [`MatcherInput`](./api-types#matcherinput) · [`CallOptions`](./api-types#calloptions) · [`ElementSummary`](./api-types#elementsummary)

マッチがちょうど1つで、それがチェックされているときに成り立ちます。対象はスイッチ、チェックボックス、ラジオ、または`accessibilityState.checked`を持つ任意の要素です。

```ts theme={null}
await app.tap({ type: SemanticType.switch, label: 'Notifications' });
await app.expectChecked({ type: SemanticType.switch, label: 'Notifications' });
```

| オプション | デフォルト | 意味 |
| - | - | - |
| `timeoutMs` | `sync.timeoutMs`（10秒） | アサーションが成立するまで再試行する最大時間 |
| `sync` | `true` | `false`：この呼び出しの前後でアプリのアイドルを待ちません（[共通オプション](https://docs.quiesco.dev/ja/api.md#call-options)） |

### `expectNotChecked(target, options?)`

```ts theme={null}
expectNotChecked(
  target: MatcherInput,
  options?: CallOptions,
): Promise<ElementSummary[]>
```

型： [`MatcherInput`](./api-types#matcherinput) · [`CallOptions`](./api-types#calloptions) · [`ElementSummary`](./api-types#elementsummary)

マッチがちょうど1つで、それがチェックされていないときに成り立ちます。

```ts theme={null}
await app.expectNotChecked({ type: SemanticType.checkbox, label: 'Remember me' });
```

| オプション | デフォルト | 意味 |
| - | - | - |
| `timeoutMs` | `sync.timeoutMs`（10秒） | アサーションが成立するまで再試行する最大時間 |
| `sync` | `true` | `false`：この呼び出しの前後でアプリのアイドルを待ちません（[共通オプション](https://docs.quiesco.dev/ja/api.md#call-options)） |

チェック状態を持たない要素は、`expectChecked`と`expectNotChecked`の両方で失敗します。

### `expectFocused(target, options?)`

```ts theme={null}
expectFocused(
  target: MatcherInput,
  options?: CallOptions,
): Promise<ElementSummary[]>
```

型： [`MatcherInput`](./api-types#matcherinput) · [`CallOptions`](./api-types#calloptions) · [`ElementSummary`](./api-types#elementsummary)

マッチがちょうど1つで、それに入力フォーカスがあるときに成り立ちます。

```ts theme={null}
await app.tap('new-todo');
await app.expectFocused('new-todo');
```

| オプション | デフォルト | 意味 |
| - | - | - |
| `timeoutMs` | `sync.timeoutMs`（10秒） | アサーションが成立するまで再試行する最大時間 |
| `sync` | `true` | `false`：この呼び出しの前後でアプリのアイドルを待ちません（[共通オプション](https://docs.quiesco.dev/ja/api.md#call-options)） |

### `expectNotFocused(target, options?)`

```ts theme={null}
expectNotFocused(
  target: MatcherInput,
  options?: CallOptions,
): Promise<ElementSummary[]>
```

型： [`MatcherInput`](./api-types#matcherinput) · [`CallOptions`](./api-types#calloptions) · [`ElementSummary`](./api-types#elementsummary)

マッチがちょうど1つで、それに入力フォーカスがないときに成り立ちます。

```ts theme={null}
await app.pressKey('new-todo', KeyName.enter);
await app.dismissKeyboard();
await app.expectNotFocused('new-todo');
```

| オプション | デフォルト | 意味 |
| - | - | - |
| `timeoutMs` | `sync.timeoutMs`（10秒） | アサーションが成立するまで再試行する最大時間 |
| `sync` | `true` | `false`：この呼び出しの前後でアプリのアイドルを待ちません（[共通オプション](https://docs.quiesco.dev/ja/api.md#call-options)） |

## チェーン形式

### `expect(target)`

```ts theme={null}
expect(target: MatcherInput): ElementExpectation
```

型： [`MatcherInput`](./api-types#matcherinput) · [`ElementExpectation`](./api-assertions#expect)

同じアサーションを、DetoxやJestのようなチェーン形式で書けます。どちらの形式も動作は同じで、アイドルを待ち、アサーションが成り立つまで再試行します。各メソッドは最後の引数に[呼び出しのオプション](https://docs.quiesco.dev/ja/api.md#call-options)を受け取り、`.not`で否定できます。

```ts theme={null}
await app.expect('save').toBeEnabled();
await app.expect({ type: SemanticType.switch, label: 'Wi-Fi' }).not.toBeChecked();

// Detoxでは toBeVisible(75)
await app.expect('promo-banner').toBeVisible({ ratio: 0.75 });

await app.expect({ id: 'todo-title', index: 0 }).not.toHaveValue('');
```

| チェーン形式 | 対応するメソッド |
| - | - |
| `toBeVisible({ ratio })` | `expectVisible`（`.not`：`expectNotVisible`） |
| `toExist()` | `expectExists`（`.not`：`expectNotExists`） |
| `toBeFocused()` | `expectFocused`（`.not`：`expectNotFocused`） |
| `toBeEnabled()` | `expectEnabled`（`.not`：`expectDisabled`） |
| `toBeDisabled()` | `expectDisabled`（`.not`：`expectEnabled`） |
| `toBeChecked()` | `expectChecked`（`.not`：`expectNotChecked`） |
| `toHaveText(text)` | `expectText` |
| `toHaveValue(value)` | `expectValue`（`Date`の形を除く） |
| `toHaveLabel(text)` | `expectLabel` |
| `toHaveProp(prop, value)` | `expectProp` |
| `toHaveCount(n)` | `expectCount` |
| `toHaveId(id)` | マッチする要素がこの`testID`（文字列または正規表現）を持つ |

1つの要素についての否定のアサーション（`not.toHaveText`、`not.toHaveValue`など）でも、マッチはちょうど1つ必要です。マッチがなければ失敗します。


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