{"record":{"id":"072cab67c4dc5ba8","repo":"vitest-dev/vitest","slug":"tohavedisplayvalue-currently-supports-only-inpu","errorCode":null,"errorMessage":".toHaveDisplayValue() currently supports only input, textarea or select elements, try with another matcher instead.","messagePattern":"\\.toHaveDisplayValue\\(\\) currently supports only input, textarea or select elements, try with another matcher instead\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/browser/src/client/tester/expect/toHaveDisplayValue.ts","lineNumber":29,"sourceCode":" *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n */\n\nimport type { MatcherResult, MatcherState } from 'vitest'\nimport 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    ),","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/browser/src/client/tester/expect/toHaveDisplayValue.ts#L11-L47","documentation":".toHaveDisplayValue() only knows how to read the value of INPUT, TEXTAREA, and SELECT elements. If the passed element has any other tag, the matcher throws rather than returning a misleading pass/fail. The check runs after element extraction and before any value comparison.","triggerScenarios":"Calling expect(divEl).toHaveDisplayValue('x') on a div/span/p/etc.; calling on an element resolved from a Locator that targeted a non-form element; refactoring that changed the queried selector.","commonSituations":"Generic assertions applied to wrapper elements; copy-paste of assertions across components without re-checking the target tag; custom elements whose tag is not in the supported list.","solutions":["Target the actual input/textarea/select element inside the wrapper.","Use a different matcher (e.g. toHaveTextContent) for non-form elements.","If testing a custom element, query its inner input first."],"exampleFix":"// before\nexpect(wrapperEl).toHaveDisplayValue('Jane')\n// after\nexpect(wrapperEl.querySelector('input')!).toHaveDisplayValue('Jane')","handlingStrategy":"type-guard","validationCode":"const SUPPORTED = ['INPUT', 'TEXTAREA', 'SELECT']\nif (!SUPPORTED.includes(el.tagName)) {\n  // pick a different matcher (e.g. toHaveTextContent)\n}\nexpect(el).toHaveDisplayValue('x')","typeGuard":"function isDisplayValueElement(el: Element): el is HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement {\n  return ['INPUT', 'TEXTAREA', 'SELECT'].includes(el.tagName)\n}","tryCatchPattern":null,"preventionTips":["Target the actual input/textarea/select element, not a wrapper.","Branch shared form-assertion helpers on element tag.","Use toHaveTextContent for non-form display text."],"tags":["browser","expect","matcher","form","display-value"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}