(html: string)
| 9 | } |
| 10 | |
| 11 | function 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 | |
| 29 | export { extractToMatchScreenshotPaths, render } |
no outgoing calls