@@ -79,10 +79,11 @@ test.describe('Mouse Behavior', () => {
79
79
await openListbox ( 'click' ) ;
80
80
81
81
const options = await getOptions ( ) ;
82
+ const thirdOptStr = await options [ 2 ] . textContent ( ) ;
82
83
await options [ 2 ] . click ( ) ;
83
84
84
85
await expect ( options [ 2 ] ) . toHaveAttribute ( 'aria-selected' , 'true' ) ;
85
- expect ( options [ 2 ] . textContent ( ) ) . toEqual ( getValue ( ) ) ;
86
+ expect ( thirdOptStr ) . toEqual ( await getValue ( ) ) ;
86
87
} ) ;
87
88
} ) ;
88
89
@@ -369,7 +370,7 @@ test.describe('Keyboard Behavior', () => {
369
370
AND the Enter key is pressed
370
371
THEN option value should be the selected value
371
372
AND should have an aria-selected of true` , async ( { page } ) => {
372
- const { getTrigger, getOptions, getValue, openListbox } = await setup (
373
+ const { getTrigger, getOptions, getValue, getListbox , openListbox } = await setup (
373
374
page ,
374
375
'select-hero-test' ,
375
376
) ;
@@ -381,9 +382,10 @@ test.describe('Keyboard Behavior', () => {
381
382
const optStr = await options [ 0 ] . textContent ( ) ;
382
383
await getTrigger ( ) . press ( 'Enter' ) ;
383
384
384
- console . log ( optStr ) ;
385
- console . log ( await getValue ( ) ) ;
386
- expect ( optStr ) . toEqual ( await getValue ( ) ) ;
385
+ // seems we need to await for the listbox to be hidden, otherwise the getValue does not update. ¯\_(ツ)_/¯
386
+ await expect ( getListbox ( ) ) . toBeHidden ( ) ;
387
+ const value = await getValue ( ) ;
388
+ expect ( optStr ) . toEqual ( value ) ;
387
389
} ) ;
388
390
389
391
test ( `GIVEN an open hero select
@@ -406,6 +408,26 @@ test.describe('Keyboard Behavior', () => {
406
408
await expect ( getListbox ( ) ) . toBeHidden ( ) ;
407
409
await expect ( getTrigger ( ) ) . toHaveAttribute ( 'aria-expanded' , 'false' ) ;
408
410
} ) ;
411
+
412
+ test ( `GIVEN an open hero select
413
+ WHEN an option has data-highlighted
414
+ AND the Space key is pressed
415
+ THEN option value should be the selected value
416
+ AND should have an aria-selected of true` , async ( { page } ) => {
417
+ const { getTrigger, getOptions, getValue, openListbox } = await setup (
418
+ page ,
419
+ 'select-hero-test' ,
420
+ ) ;
421
+
422
+ await openListbox ( 'Space' ) ;
423
+
424
+ const options = await getOptions ( ) ;
425
+ await expect ( options [ 0 ] ) . toHaveAttribute ( 'data-highlighted' ) ;
426
+ const optStr = await options [ 0 ] . textContent ( ) ;
427
+ await getTrigger ( ) . press ( 'Space' ) ;
428
+
429
+ expect ( optStr ) . toEqual ( await getValue ( ) ) ;
430
+ } ) ;
409
431
} ) ;
410
432
} ) ;
411
433
0 commit comments