Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hasAria() docs and add hasNoAria() and lacksAria() aliases #1481

Merged
merged 4 commits into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/__tests__/has-aria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ describe('assert.dom(...).hasAria()', () => {
test('smoke test', () => {
assert.dom('button').hasAria('pressed', 'true');
assert.dom('button').doesNotHaveAria('hidden');
assert.dom('button').hasNoAria('hidden');
assert.dom('button').lacksAria('hidden');

expect(assert.results).toEqual([
{
Expand All @@ -29,6 +31,18 @@ describe('assert.dom(...).hasAria()', () => {
message: 'Element button does not have attribute "aria-hidden"',
result: true,
},
{
actual: 'Element button does not have attribute "aria-hidden"',
expected: 'Element button does not have attribute "aria-hidden"',
message: 'Element button does not have attribute "aria-hidden"',
result: true,
},
{
actual: 'Element button does not have attribute "aria-hidden"',
expected: 'Element button does not have attribute "aria-hidden"',
message: 'Element button does not have attribute "aria-hidden"',
result: true,
},
]);
});
});
14 changes: 12 additions & 2 deletions lib/assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ export default class DOMAssertions {
* @param {string?} message
*
* @example
* assert.dom('input.username').hasNoAttribute('disabled');
* assert.dom('input.username').doesNotHaveAttribute('disabled');
*
* @see {@link #hasAttribute}
*/
Expand Down Expand Up @@ -492,7 +492,7 @@ export default class DOMAssertions {
* @example
* assert.dom('button').hasAria('pressed', 'true');
*
* @see {@link #hasNoAria}
* @see {@link #doesNotHaveAria}
*/
hasAria(name: string, value?: string | RegExp | { any: true }, message?: string): DOMAssertions {
return this.hasAttribute(`aria-${name}`, value, message);
Expand All @@ -502,6 +502,8 @@ export default class DOMAssertions {
* Assert that the {@link HTMLElement} has no ARIA attribute with the
* provided `name`.
*
* **Aliases:** `hasNoAria`, `lacksAria`
*
* @param {string} name
* @param {string?} message
*
Expand All @@ -514,6 +516,14 @@ export default class DOMAssertions {
return this.doesNotHaveAttribute(`aria-${name}`, message);
}

hasNoAria(name: string, message?: string): DOMAssertions {
return this.doesNotHaveAria(name, message);
}

lacksAria(name: string, message?: string): DOMAssertions {
return this.doesNotHaveAria(name, message);
}

/**
* Assert that the {@link HTMLElement} has a property with the provided `name`
* and checks if the property `value` matches the provided text or regular
Expand Down