Skip to content

Commit 24c3d68

Browse files
fix(tests): missed await behavior
1 parent a92aca9 commit 24c3d68

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

apps/website/src/routes/docs/headless/select/select.driver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export function createTestDriver<T extends DriverLocator>(locator: T) {
1919
return getRoot().getByRole('option', { includeHidden: true }).all();
2020
};
2121

22-
const getValue = () => {
23-
return getTrigger().locator('[data-value]').textContent();
22+
const getValue = async () => {
23+
return await getTrigger().locator('[data-value]').textContent();
2424
};
2525

2626
const openListbox = async (key: OpenKeys | 'click') => {

apps/website/src/routes/docs/headless/select/select.spec.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ test.describe('Mouse Behavior', () => {
7979
await openListbox('click');
8080

8181
const options = await getOptions();
82+
const thirdOptStr = await options[2].textContent();
8283
await options[2].click();
8384

8485
await expect(options[2]).toHaveAttribute('aria-selected', 'true');
85-
expect(options[2].textContent()).toEqual(getValue());
86+
expect(thirdOptStr).toEqual(await getValue());
8687
});
8788
});
8889

@@ -369,7 +370,7 @@ test.describe('Keyboard Behavior', () => {
369370
AND the Enter key is pressed
370371
THEN option value should be the selected value
371372
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(
373374
page,
374375
'select-hero-test',
375376
);
@@ -381,9 +382,10 @@ test.describe('Keyboard Behavior', () => {
381382
const optStr = await options[0].textContent();
382383
await getTrigger().press('Enter');
383384

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);
387389
});
388390

389391
test(`GIVEN an open hero select
@@ -406,6 +408,26 @@ test.describe('Keyboard Behavior', () => {
406408
await expect(getListbox()).toBeHidden();
407409
await expect(getTrigger()).toHaveAttribute('aria-expanded', 'false');
408410
});
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+
});
409431
});
410432
});
411433

0 commit comments

Comments
 (0)