{"record":{"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/1fa9837ec26533512fdcad8baebf249771bd340a/packages/browser/src/client/tester/expect/toHaveDisplayValue.ts#L17-L53","documentation":".toHaveDisplayValue() does not support INPUT elements of type radio or checkbox, because their meaningful state is `checked`, not `value`. Vitest throws with the specific type interpolated when it detects such an input, directing the user to a more appropriate matcher (e.g. toBeChecked()). This guard fires after the tag-name check passes.","triggerScenarios":"Calling expect(radioInput).toHaveDisplayValue('on') or expect(checkboxInput).toHaveDisplayValue(...); applying a generic display-value assertion to a form that includes radio/checkbox inputs without distinguishing by type.","commonSituations":"Reusable form assertion helpers that apply toHaveDisplayValue uniformly to all inputs; copy-pasted assertions across input types.","solutions":["For radio/checkbox, use expect(el).toBeChecked() (or .not.toBeChecked()) instead.","If you really need the value attribute, assert on el.getAttribute('value') directly.","Branch the assertion helper on input.type before picking a matcher."],"exampleFix":"// before\nexpect(checkboxEl).toHaveDisplayValue('on')\n// after\nexpect(checkboxEl).toBeChecked()","handlingStrategy":"type-guard","validationCode":"if (el instanceof HTMLInputElement && ['radio', 'checkbox'].includes(el.type)) {\n  // use toBeChecked instead of toHaveDisplayValue\n}\nexpect(el).toBeChecked()","typeGuard":"function isToggleInput(el: Element): el is HTMLInputElement & { type: 'radio' | 'checkbox' } {\n  return el instanceof HTMLInputElement && ['radio', 'checkbox'].includes(el.type)\n}","tryCatchPattern":null,"preventionTips":["Use toBeChecked for radio/checkbox inputs.","Branch form-assertion helpers on input.type.","Document which input types each matcher supports."],"tags":["browser","expect","matcher","form","input-type"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}