{"id":"806006a4bc3ca3bd","repo":"vitest-dev/vitest","slug":"tohavedisplayvalue-currently-does-not-support-i","errorCode":null,"errorMessage":".toHaveDisplayValue() currently does not support input[type=\"${htmlElement.type}\"], try with another matcher instead.","messagePattern":"\\.toHaveDisplayValue\\(\\) currently does not support input\\[type=\"(.+?)\"\\], try with another matcher instead\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/browser/src/client/tester/expect/toHaveDisplayValue.ts","lineNumber":35,"sourceCode":"import type { Locator } from '../locators'\nimport { getElementFromUserInput, getMessage, getTag, isInputElement } from './utils'\n\nexport default function toHaveDisplayValue(\n  this: MatcherState,\n  actual: Element | Locator,\n  expectedValue: string | RegExp | Array<string | RegExp>,\n): MatcherResult {\n  const htmlElement = getElementFromUserInput(actual, toHaveDisplayValue, this)\n  const tagName = getTag(htmlElement)\n\n  if (!['SELECT', 'INPUT', 'TEXTAREA'].includes(tagName)) {\n    throw new Error(\n      '.toHaveDisplayValue() currently supports only input, textarea or select elements, try with another matcher instead.',\n    )\n  }\n\n  if (isInputElement(htmlElement) && ['radio', 'checkbox'].includes(htmlElement.type)) {\n    throw new Error(\n      `.toHaveDisplayValue() currently does not support input[type=\"${htmlElement.type}\"], try with another matcher instead.`,\n    )\n  }\n\n  const values = getValues(tagName, htmlElement)\n  const expectedValues = getExpectedValues(expectedValue)\n  const numberOfMatchesWithValues = expectedValues.filter(expected =>\n    values.some(value =>\n      expected instanceof RegExp\n        ? expected.test(value)\n        : this.equals(value, String(expected), this.customTesters),\n    ),\n  ).length\n\n  const matchedWithAllValues = numberOfMatchesWithValues === values.length\n  const matchedWithAllExpectedValues\n    = numberOfMatchesWithValues === expectedValues.length\n","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/browser/src/client/tester/expect/toHaveDisplayValue.ts#L17-L53","documentation":"Thrown by toHaveDisplayValue (packages/browser/src/client/tester/expect/toHaveDisplayValue.ts:34-38) when the element IS an <input> but its type is 'radio' or 'checkbox'. Those input types carry checked state, not a textual display value, so reading .value is semantically wrong; the matcher refuses them and points to a more appropriate matcher.","triggerScenarios":"Calling expect(checkboxEl).toHaveDisplayValue('true') or expect(radioEl).toHaveDisplayValue('option1') on an <input type=\"checkbox\"> or <input type=\"radio\">.","commonSituations":"Generic form helpers that apply toHaveDisplayValue to all inputs; tests written for text inputs copied onto toggle inputs without changing the matcher.","solutions":["For checked state, use toBeChecked() / expect(el).toBeChecked() or toHaveProperty('checked', true).","For the value attribute, use toHaveAttribute('value', '...').","If you genuinely need the option's label text, query the associated <label> or option element and use toHaveText."],"exampleFix":"// before\nexpect(checkboxEl).toHaveDisplayValue('on')\n// after\nexpect(checkboxEl).toBeChecked()\n// or, for the value attribute:\nexpect(checkboxEl).toHaveAttribute('value', 'on')","handlingStrategy":"validation","validationCode":"function isTextualInput(el: Element): el is HTMLInputElement {\n  return el instanceof HTMLInputElement\n    && !['radio', 'checkbox'].includes(el.type)\n}\nconst el = /* your element */\nif (isTextualInput(el) || el instanceof HTMLTextAreaElement || el instanceof HTMLSelectElement) {\n  expect(el).toHaveDisplayValue('...')\n} else if (el instanceof HTMLInputElement && ['radio','checkbox'].includes(el.type)) {\n  expect(el).toBeChecked()\n}","typeGuard":"function isToggleInput(el: Element): el is HTMLInputElement {\n  return el instanceof HTMLInputElement && ['radio', 'checkbox'].includes(el.type)\n}","tryCatchPattern":null,"preventionTips":["For checkbox/radio inputs use toBeChecked or toHaveAttribute('value').","Reserve toHaveDisplayValue for text inputs, textareas, and selects."],"tags":["browser","expect","matcher","tohavedisplayvalue","checkbox","radio","form"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}