MCPcopy
hub / github.com/vitest-dev/vitest / render

Function render

test/browser/fixtures/expect-dom/utils.ts:11–27  ·  view source on GitHub ↗
(html: string)

Source from the content-addressed store, hash-verified

9}
10
11function render(html: string) {
12 const container = document.createElement('div')
13 container.innerHTML = html
14 const queryByTestId = (testId: string) =>
15 container.querySelector(`[data-testid="${testId}"]`) as HTMLElement | SVGElement | null
16 // asFragment has been stolen from react-testing-library
17 const asFragment = () =>
18 document.createRange().createContextualFragment(container.innerHTML)
19 const getInputByTestId = (testId: string) => queryByTestId(testId) as HTMLInputElement
20
21 // Some tests need to look up global ids with document.getElementById()
22 // so we need to be inside an actual document.
23 document.body.innerHTML = ''
24 document.body.appendChild(container)
25
26 return { container, queryByTestId, asFragment, getInputByTestId }
27}
28
29export { extractToMatchScreenshotPaths, render }

Callers 15

mountFunction · 0.90
renderFormFunction · 0.90

Calls

no outgoing calls

Tested by 5

mountFunction · 0.72
renderFormFunction · 0.72
renderFieldWithStateFunction · 0.72
renderTestCaseFunction · 0.72
renderElementWithClassesFunction · 0.72