Skip to content

Commit

Permalink
Migrate custom childrens test to RTL
Browse files Browse the repository at this point in the history
  • Loading branch information
davesnx committed Nov 25, 2024
1 parent 05ecc63 commit e017f0b
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions test/React__test.re
Original file line number Diff line number Diff line change
Expand Up @@ -447,28 +447,27 @@ describe("React", () => {
});

test("Can define components with custom children", () => {
let container = getContainer(container);
let root = ReactDOM.Client.createRoot(container);

module Test = {
type t = {name: string};
[@react.component]
let make = (~children) => {
Array.map(children, c =>
<div name={c.name}> {React.string(c.name)} </div>
)
->React.array;
React.array(
Belt.Array.map(children, c =>
<div role={c.name}> {React.string(c.name)} </div>
),
);
};
};

act(() => {
ReactDOM.Client.render(
root,
let container =
ReactTestingLibrary.render(
<Test> {Test.name: "foo"} {name: "bar"} </Test>,
)
});
);

let foo = getByRole("foo", container);
expect(foo->innerHTML)->toBe("foo");

expect(container->DOM.findBySelector("div[name='foo']")->Option.isSome)
->toBe(true);
let bar = getByRole("bar", container);
expect(bar->innerHTML)->toBe("bar");
});
});

0 comments on commit e017f0b

Please sign in to comment.