feat(aria): extend toHaveAccessibleName() to accept an array of expected accessible names

This commit extends the toHaveAccessibleName() matcher to support an array

References #32593
This commit is contained in:
anait-airiian 2024-10-24 18:26:01 +02:00
parent 9a6e1b71a4
commit 459914c5cc
2 changed files with 14 additions and 7 deletions

View file

@ -189,13 +189,20 @@ export function toHaveAccessibleDescription(
export function toHaveAccessibleName( export function toHaveAccessibleName(
this: ExpectMatcherState, this: ExpectMatcherState,
locator: LocatorEx, locator: LocatorEx,
expected: string | RegExp, expected: string | RegExp | (string | RegExp)[],
options?: { timeout?: number, ignoreCase?: boolean }, options: { timeout?: number, ignoreCase?: boolean, normalizeWhiteSpace?: boolean } = {}
) { ) {
return toMatchText.call(this, 'toHaveAccessibleName', locator, 'Locator', async (isNot, timeout) => { if (Array.isArray(expected)) {
const expectedText = serializeExpectedTextValues([expected], { ignoreCase: options?.ignoreCase }); return toEqual.call(this, 'toHaveAccessibleName', locator, 'Locator', async (isNot, timeout) => {
return await locator._expect('to.have.accessible.name', { expectedText, isNot, timeout }); const expectedText = serializeExpectedTextValues(expected, { normalizeWhiteSpace: true, ignoreCase: options.ignoreCase });
}, expected, options); return await locator._expect('to.have.accessible.name.array', { expectedText, isNot, timeout });
}, expected, options);
} else {
return toMatchText.call(this, 'toHaveAccessibleName', locator, 'Locator', async (isNot, timeout) => {
const expectedText = serializeExpectedTextValues([expected], { normalizeWhiteSpace: true, ignoreCase: options.ignoreCase });
return await locator._expect('to.have.accessible.name', { expectedText, isNot, timeout });
}, expected, options);
}
} }
export function toHaveAttribute( export function toHaveAttribute(

View file

@ -7898,7 +7898,7 @@ interface LocatorAssertions {
* @param name Expected accessible name. * @param name Expected accessible name.
* @param options * @param options
*/ */
toHaveAccessibleName(name: string|RegExp, options?: { toHaveAccessibleName(name: string | RegExp | (string | RegExp)[], options?: {
/** /**
* Whether to perform case-insensitive match. * Whether to perform case-insensitive match.
* [`ignoreCase`](https://playwright.dev/docs/api/class-locatorassertions#locator-assertions-to-have-accessible-name-option-ignore-case) * [`ignoreCase`](https://playwright.dev/docs/api/class-locatorassertions#locator-assertions-to-have-accessible-name-option-ignore-case)