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: Give select a more useful error message. #1083

Merged
merged 1 commit into from
Oct 18, 2024
Merged
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: 6 additions & 8 deletions src/utils/rtl.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { newLocation as _newLocation, withRouter as _withRouter } from "@homebound/rtl-react-router-utils";
import { withRouter as _withRouter } from "@homebound/rtl-react-router-utils";
import {
blur as _blur,
change as _change,
click as _click,
clickAndWait as _clickAndWait,
focus as _focus,
getOptions as _getOptions,
input as _input,
select as _select,
type as _type,
typeAndWait as _typeAndWait,
wait as _wait,
Expand All @@ -17,19 +15,16 @@ import {
Wrapper,
} from "@homebound/rtl-utils";
import { prettyDOM } from "@testing-library/react";
import { fail } from "mobx-utils";
import { ReactElement } from "react";
import { BeamProvider } from "src/components";
import { fail } from "src/utils/index";
export {
_blur as blur,
_change as change,
_click as click,
_clickAndWait as clickAndWait,
_focus as focus,
_input as input,
_newLocation as newLocation,
_getOptions as rtlUtilGetOptions,
_select as rtlUtilSelect,
_type as type,
_typeAndWait as typeAndWait,
_wait as wait,
Expand Down Expand Up @@ -277,7 +272,10 @@ export function getOptions(select: HTMLElement): string[] {
}

function findListBox(select: HTMLElement): HTMLElement {
const listboxId = select.getAttribute("aria-controls") || fail("aria-controls attribute not found");
if (select.tagName === "DIV") fail("SelectField is readOnly");
const listboxId =
select.getAttribute("aria-controls") ||
fail("aria-controls attribute not found, the SelectField is probably readOnly");
return document.getElementById(listboxId) || fail("listbox not found");
}

Expand Down
Loading