Skip to content

Commit

Permalink
Add jest test for ref
Browse files Browse the repository at this point in the history
  • Loading branch information
davesnx committed Nov 20, 2024
1 parent 507b0fb commit f3dc9f3
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/Ref__test.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
open Jest;
open Expect;

module Button_with_ref = {
[@react.component]
let make = (~children, ~ref) => {
<button ref role="FancyButton"> children </button>;
};
};

let getByRole = (role, container) => {
ReactTestingLibrary.getByRole(~matcher=`Str(role), container);
};

[@mel.get] external innerHTML: Dom.element => string = "innerHTML";

describe("ref", () => {
test("can be passed as prop to a component", () => {
let domRef = React.createRef();
let container =
ReactTestingLibrary.render(
<Button_with_ref ref={ReactDOM.Ref.domRef(domRef)}>
{React.string("Click me")}
</Button_with_ref>,
);
let button = getByRole("FancyButton", container);
expect(button->innerHTML)->toBe("Click me");
})
});

0 comments on commit f3dc9f3

Please sign in to comment.