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:
parent
9a6e1b71a4
commit
459914c5cc
|
|
@ -189,13 +189,20 @@ export function toHaveAccessibleDescription(
|
|||
export function toHaveAccessibleName(
|
||||
this: ExpectMatcherState,
|
||||
locator: LocatorEx,
|
||||
expected: string | RegExp,
|
||||
options?: { timeout?: number, ignoreCase?: boolean },
|
||||
expected: string | RegExp | (string | RegExp)[],
|
||||
options: { timeout?: number, ignoreCase?: boolean, normalizeWhiteSpace?: boolean } = {}
|
||||
) {
|
||||
if (Array.isArray(expected)) {
|
||||
return toEqual.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.array', { expectedText, isNot, timeout });
|
||||
}, expected, options);
|
||||
} else {
|
||||
return toMatchText.call(this, 'toHaveAccessibleName', locator, 'Locator', async (isNot, timeout) => {
|
||||
const expectedText = serializeExpectedTextValues([expected], { ignoreCase: options?.ignoreCase });
|
||||
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(
|
||||
|
|
|
|||
2
packages/playwright/types/test.d.ts
vendored
2
packages/playwright/types/test.d.ts
vendored
|
|
@ -7898,7 +7898,7 @@ interface LocatorAssertions {
|
|||
* @param name Expected accessible name.
|
||||
* @param options
|
||||
*/
|
||||
toHaveAccessibleName(name: string|RegExp, options?: {
|
||||
toHaveAccessibleName(name: string | RegExp | (string | RegExp)[], options?: {
|
||||
/**
|
||||
* Whether to perform case-insensitive match.
|
||||
* [`ignoreCase`](https://playwright.dev/docs/api/class-locatorassertions#locator-assertions-to-have-accessible-name-option-ignore-case)
|
||||
|
|
|
|||
Loading…
Reference in a new issue