@@ -358,29 +358,34 @@ export class ElementAssertion<T extends Element> extends Assertion<T> {
358358 /**
359359 * Asserts that the element is a pressed button.
360360 *
361+ * @example
362+ * const toggleButton = document.querySelector('#toggle');
363+ * expect(toggleButton).toBePressed(); // passes if aria-pressed="true"
364+ * expect(toggleButton).not.toBePressed(); // fails if aria-pressed="true"
365+ *
361366 * @returns the assertion instance.
362367 */
363368
364369 public toBePressed ( ) : this {
365370 if ( ! isButtonElement ( this . actual ) || ! isValidAriaPressed ( this . actual ) ) {
366371 throw new Error (
367- '.toBePressed() requires a button, input[type="button"], or role=" button" with valid aria- pressed' ,
372+ 'Expected a button or button-like control with a valid pressed state: "true", "false", or "mixed". ' ,
368373 ) ;
369374 }
370375
371- const pressedAttribute = this . actual . getAttribute ( "aria-pressed" ) ;
372- const isPressed = pressedAttribute === "true" ;
376+ const pressedAttributeValue = this . actual . getAttribute ( "aria-pressed" ) ;
377+ const isPressed = pressedAttributeValue === "true" ;
373378
374379 const error = new AssertionError ( {
375- actual : pressedAttribute ,
380+ actual : pressedAttributeValue ,
376381 expected : "true" ,
377- message : `Expected the element to be pressed, but received aria-pressed="${ pressedAttribute } "` ,
382+ message : `Expected the element to be pressed, but received aria-pressed="${ pressedAttributeValue } "` ,
378383 } ) ;
379384
380385 const invertedError = new AssertionError ( {
381- actual : pressedAttribute ,
386+ actual : pressedAttributeValue ,
382387 expected : "false" ,
383- message : `Expected the element to NOT be pressed, but received aria-pressed="${ pressedAttribute } "` ,
388+ message : `Expected the element to NOT be pressed, but received aria-pressed="${ pressedAttributeValue } "` ,
384389 } ) ;
385390
386391 return this . execute ( {
@@ -393,28 +398,35 @@ export class ElementAssertion<T extends Element> extends Assertion<T> {
393398 /**
394399 * Asserts that the element is a partially pressed button.
395400 *
401+ * @example
402+ * const toggleButton = document.querySelector('#toggle');
403+ * expect(toggleButton).toBePartiallyPressed();
404+ * // passes if aria-pressed="mixed"
405+ * expect(toggleButton).not.toBePartiallyPressed();
406+ * // fails if aria-pressed="mixed"
407+ *
396408 * @returns the assertion instance.
397409 */
398410
399411 public toBePartiallyPressed ( ) : this {
400412 if ( ! isButtonElement ( this . actual ) || ! isValidAriaPressed ( this . actual ) ) {
401413 throw new Error (
402- '.toBePartiallyPressed() requires a button, input[type="button"], or role=" button" with valid aria- pressed' ,
414+ 'Expected a button or button-like control with a valid pressed state: "true", "false", or "mixed". ' ,
403415 ) ;
404416 }
405417
406- const pressedAttribute = this . actual . getAttribute ( "aria-pressed" ) ;
407- const isPartiallyPressed = pressedAttribute === "mixed" ;
418+ const pressedAttributeValue = this . actual . getAttribute ( "aria-pressed" ) ;
419+ const isPartiallyPressed = pressedAttributeValue === "mixed" ;
408420
409421 const error = new AssertionError ( {
410- actual : pressedAttribute ,
422+ actual : pressedAttributeValue ,
411423 expected : "mixed" ,
412- message : `Expected the element to be partially pressed, but received aria-pressed="${ pressedAttribute } "` ,
424+ message : `Expected the element to be partially pressed, but received aria-pressed="${ pressedAttributeValue } "` ,
413425 } ) ;
414426
415427 const invertedError = new AssertionError ( {
416- actual : pressedAttribute ,
417- message : `Expected the element to NOT be partially pressed, but received aria-pressed="${ pressedAttribute } "` ,
428+ actual : pressedAttributeValue ,
429+ message : `Expected the element to NOT be partially pressed, but received aria-pressed="${ pressedAttributeValue } "` ,
418430 } ) ;
419431
420432 return this . execute ( {
0 commit comments