Skip to content

Commit

Permalink
use the new inputRef property instead of relying on the query selector (
Browse files Browse the repository at this point in the history
  • Loading branch information
alexasselin008 authored May 10, 2024
2 parents a2480a3 + 05060b8 commit f8f4dc1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/components/src/switch/tests/jest/Switch.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* Using closest to get the label is the best way, even react-aria does this. */
import { act, screen, waitFor, render } from "@hopper-ui/test-utils";
import { userEvent } from "@testing-library/user-event";
import { createRef } from "react";
import { createRef, type MutableRefObject } from "react";

import { Switch } from "../../src/Switch.tsx";
import { SwitchContext } from "../../src/SwitchContext.ts";
Expand Down Expand Up @@ -47,7 +47,7 @@ describe("Switch", () => {

const switchElem = screen.getByRole("switch");
const element = switchElem.closest("label");

expect(element).toHaveAttribute("slot", "test");
expect(switchElem).toHaveAttribute("aria-label", "test");
});
Expand Down Expand Up @@ -82,10 +82,11 @@ describe("Switch", () => {
// ***** Api *****

it("should be focused on render when the focus api is called", async () => {
const ref = createRef<HTMLLabelElement>();
const ref = createRef<HTMLInputElement>() as MutableRefObject<HTMLInputElement>;

render(<Switch ref={ref}>option 1</Switch>);
const switchElement = ref.current?.querySelector("input[type='checkbox']") as HTMLInputElement;
render(<Switch inputRef={ref} >option 1</Switch>);

const switchElement = ref.current;

act(() => {
switchElement?.focus();
Expand Down

0 comments on commit f8f4dc1

Please sign in to comment.