本編へスキップ

ByTitle

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

一致する title 属性を持つ要素を返します。

SVG 内の title 要素も検索します。

<span title="Delete" id="2"></span>
<svg>
<title>Close</title>
<g><path /></g>
</svg>
import {screen} from '@testing-library/dom'

const deleteElement = screen.getByTitle('Delete')
const closeElement = screen.getByTitle('Close')

オプション

テキスト一致 オプション