Skip to content

Commit d5a665b

Browse files
committed
test: add example for attemtping to click SVG title
1 parent 401f2ce commit d5a665b

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

test/fixture/locators.test.ts

+19
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,25 @@ test.describe('lib/fixture.ts (locators)', () => {
119119
expect(await hiddenElements.count()).toEqual(2)
120120
})
121121

122+
test.only('supports querying SVG by title', async ({screen}) => {
123+
const svg = screen.getByRole('img', {name: 'Vector'})
124+
125+
expect(await svg.count()).toEqual(1)
126+
127+
await expect(svg.click()).resolves.not.toThrow()
128+
})
129+
130+
test.only('clicking SVG title element', async ({screen, within}) => {
131+
const svg = screen.getByRole('img', {name: 'Vector'})
132+
const title = within(svg).getByText('Vector')
133+
134+
screen.setDefaultTimeout(1000)
135+
136+
expect(await title.count()).toEqual(1)
137+
138+
await expect(async () => title.click()).rejects.toThrow()
139+
})
140+
122141
test.describe('querying by role with `level` option', () => {
123142
test('retrieves the correct elements when querying all by role', async ({
124143
queries: {queryAllByRole},

test/fixtures/page.html

+12-2
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,23 @@ <h3>Hello h3</h3>
2626
>
2727
<path d="M502.3 190.8c3.9-3.1 9.7-.2 9.7 4.7V400c0 26.5-21.5 48-48 48H48c-26.5 0-48-21.5-48-48V195.6c0-5 5.7-7.8 9.7-4.7 22.4 17.4 52.1 39.5 154.1 113.6 21.1 15.4 56.7 47.8 92.2 47.6 35.7.3 72-32.8 92.3-47.6 102-74.1 131.6-96.3 154-113.7zM256 320c23.2.4 56.6-29.2 73.4-41.4 132.7-96.3 142.8-104.7 173.4-128.7 5.8-4.5 9.2-11.5 9.2-18.9v-19c0-26.5-21.5-48-48-48H48C21.5 64 0 85.5 0 112v19c0 7.4 3.4 14.3 9.2 18.9 30.6 23.9 40.7 32.4 173.4 128.7 16.8 12.2 50.2 41.8 73.4 41.4z" />
2828
</svg>
29+
30+
<svg
31+
role="img"
32+
xmlns="http://www.w3.org/2000/svg"
33+
width="128px"
34+
viewBox="0 0 512 512"
35+
>
36+
<title>Vector</title>
37+
<path d="M502.3 190.8c3.9-3.1 9.7-.2 9.7 4.7V400c0 26.5-21.5 48-48 48H48c-26.5 0-48-21.5-48-48V195.6c0-5 5.7-7.8 9.7-4.7 22.4 17.4 52.1 39.5 154.1 113.6 21.1 15.4 56.7 47.8 92.2 47.6 35.7.3 72-32.8 92.3-47.6 102-74.1 131.6-96.3 154-113.7zM256 320c23.2.4 56.6-29.2 73.4-41.4 132.7-96.3 142.8-104.7 173.4-128.7 5.8-4.5 9.2-11.5 9.2-18.9v-19c0-26.5-21.5-48-48-48H48C21.5 64 0 85.5 0 112v19c0 7.4 3.4 14.3 9.2 18.9 30.6 23.9 40.7 32.4 173.4 128.7 16.8 12.2 50.2 41.8 73.4 41.4z" />
38+
</svg>
2939
</body>
30-
40+
3141
<form>
3242
<label for="#name">Name</label>
3343
<input id="name" name="name" type="text" />
3444
</form>
35-
45+
3646
<label id="user-label">User</label>
3747
<form aria-labelledby="user-label">
3848
<label for="username">Username</label>

0 commit comments

Comments
 (0)