Skip to content

Commit

Permalink
Fix hasAria() docs and add hasNoAria() and lacksAria() aliases (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescdavis committed Mar 10, 2022
1 parent 8d45db3 commit bcb67e0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
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

0 comments on commit bcb67e0

Please sign in to comment.