Claude Opus 5.5

vitest-5-0-0-7-b

Claude Code's read-only tools, web search on, ludion sync on

Question

How do I check that an element's text contains a phrase in Vitest browser mode?

Answer key

A correct answer says
toHaveTextContent now matches strictly; use the new toMatchTextContent for partial matching.
The stale answer
toHaveTextContent('foo') passes when the text merely contains 'foo'.

The change's lesson

Answer

Use `toMatchTextContent`: `await expect.element(el).toMatchTextContent('phrase')`. It also accepts a RegExp, such as `/phrase/i` for a case-insensitive match.

Don't use `toHaveTextContent` for this. In the installed vitest 5.x it only passes when the text matches exactly, so a partial phrase fails. Older code written for the earlier partial-match behaviour won't throw an error; those assertions will just start failing. The installed types say the same thing (`node_modules/@vitest/browser/jest-dom.d.ts:408`).

Answering cost $0.09.

Grade

correct

The judge's reason: It recommends toMatchTextContent for partial matching and states toHaveTextContent now requires an exact match, with no stale claim.

The judge's log

Session log

What the agent wrote, the tools it called, and what they returned, from docs/bench/2026-10-11-done3/runs/B-project-sync/vitest-5-0-0-7-b.jsonl. Thinking and the session's settings are left out. The raw log

  1. Tool call: Grep

    {
      "pattern": "toMatchTextContent|toHaveTextContent",
      "path": "C:\\Users\\haya0\\AppData\\Local\\Temp\\ludion-bench-zKtsex\\work\\node_modules",
      "glob": "*.d.ts",
      "output_mode": "content",
      "head_limit": 20
    }
  2. Tool output

    node_modules\@vitest\browser\jest-dom.d.ts:408:   * If you wish to perform a partial check or use a RegExp, use `toMatchTextContent` instead.
    node_modules\@vitest\browser\jest-dom.d.ts:413:   * await expect.element(element).toHaveTextContent('Text Content')
    node_modules\@vitest\browser\jest-dom.d.ts:414:   * await expect.element(element).not.toHaveTextContent('Content')
    node_modules\@vitest\browser\jest-dom.d.ts:417:  toHaveTextContent(text: string | number, options?: { normalizeWhitespace: boolean }): R
    node_modules\@vitest\browser\jest-dom.d.ts:432:   * await expect.element(element).toMatchTextContent('Content')
    node_modules\@vitest\browser\jest-dom.d.ts:434:   * await expect.element(element).toMatchTextContent(/^Text Content$/)
    node_modules\@vitest\browser\jest-dom.d.ts:436:   * await expect.element(element).toMatchTextContent(/content$/i)
    node_modules\@vitest\browser\jest-dom.d.ts:437:   * await expect.element(element).not.toMatchTextContent('content')
    node_modules\@vitest\browser\jest-dom.d.ts:440:  toMatchTextContent(text: string | number | RegExp, options?: { normalizeWhitespace: boolean }): R
  3. Agent

    Use `toMatchTextContent`: `await expect.element(el).toMatchTextContent('phrase')`. It also accepts a RegExp, such as `/phrase/i` for a case-insensitive match.
    
    Don't use `toHaveTextContent` for this. In the installed vitest 5.x it only passes when the text matches exactly, so a partial phrase fails. Older code written for the earlier partial-match behaviour won't throw an error; those assertions will just start failing. The installed types say the same thing (`node_modules/@vitest/browser/jest-dom.d.ts:408`).