getByTitle, queryByTitle, getAllByTitle, queryAllByTitle, findByTitle, findAllByTitle
API
getByTitle(
// If you're using `screen`, then skip the container argument:
container: HTMLElement,
title: TextMatch,
options?: {
exact?: boolean = true,
normalizer?: NormalizerFn,
}): HTMLElement
返回具有匹配标题属性的元素。还将在SVG中查找标题元素。
<span title="Delete" id="2"></span>
<svg>
<title>Close</title>
<g><path /></g>
</svg>
// HTML
import {screen} from '@testing-library/dom'
const deleteElement = screen.getByTitle('Delete')
const closeElement = screen.getByTitle('Close')
// React
import {render, screen} from '@testing-library/react'
render(<MyComponent />)
const deleteElement = screen.getByTitle('Delete')
const closeElement = screen.getByTitle('Close')