feat(aria): handle array in the injectedScript and write a test
This commit includes the handling accessible.name.array References #32593
This commit is contained in:
parent
459914c5cc
commit
7456dea563
|
|
@ -1324,6 +1324,8 @@ export class InjectedScript {
|
|||
received = elements.map(e => options.useInnerText ? (e as HTMLElement).innerText : elementText(new Map(), e).full);
|
||||
else if (expression === 'to.have.class.array')
|
||||
received = elements.map(e => e.classList.toString());
|
||||
else if (expression === 'to.have.accessible.name.array')
|
||||
received = elements.map(e => getElementAccessibleName(e, false));
|
||||
|
||||
if (received && options.expectedText) {
|
||||
// "To match an array" is "to contain an array" + "equal length"
|
||||
|
|
|
|||
|
|
@ -433,6 +433,33 @@ test('toHaveAccessibleName', async ({ page }) => {
|
|||
await expect(page.locator('div')).toHaveAccessibleName(/hello/, { ignoreCase: true });
|
||||
});
|
||||
|
||||
test('toHaveAccessibleName should accept array of names for multiple elements', async ({ page }) => {
|
||||
await page.setContent(`
|
||||
<table>
|
||||
<tr role="row">
|
||||
<td role="cell">Cell A1</td>
|
||||
<td role="cell">Cell B1</td>
|
||||
<td role="cell">Cell C1</td>
|
||||
</tr>
|
||||
<tr role="row">
|
||||
<td role="cell">Cell A2</td>
|
||||
<td role="cell">Cell B2</td>
|
||||
<td role="cell">Cell C2</td>
|
||||
</tr>
|
||||
<tr role="row">
|
||||
<td role="cell">Cell A3</td>
|
||||
<td role="cell">Cell B3</td>
|
||||
<td role="cell">Cell C3</td>
|
||||
</tr>
|
||||
</table>
|
||||
`);
|
||||
await expect(page.getByRole('row')).toHaveAccessibleName([
|
||||
'Cell A1 Cell B1 Cell C1',
|
||||
'Cell A2 Cell B2 Cell C2',
|
||||
'Cell A3 Cell B3 Cell C3',
|
||||
]);
|
||||
});
|
||||
|
||||
test('toHaveAccessibleDescription', async ({ page }) => {
|
||||
await page.setContent(`
|
||||
<div role="button" aria-description="Hello"></div>
|
||||
|
|
|
|||
Loading…
Reference in a new issue