@@ -16,17 +16,15 @@ module DummyComponentThatMapsChildren = {
1616 [@ react . component ]
1717 let make = (~children, () ) => {
1818 <div >
19- {children
20- -> React . array
21- -> React . Children . mapWithIndex((element, index) => {
22- React . cloneElement(
23- element,
24- {
25- "key" : string_of_int(index),
26- "role" : Int . to_string(index),
27- },
28- )
29- })}
19+ {children-> React . Children . mapWithIndex((element, index) => {
20+ React . cloneElement(
21+ element,
22+ {
23+ "key" : string_of_int(index),
24+ "role" : Int . to_string(index),
25+ },
26+ )
27+ })}
3028 </div >;
3129 };
3230};
@@ -170,9 +168,11 @@ describe("React", () => {
170168 let container =
171169 ReactTestingLibrary . render(
172170 <DummyComponentThatMapsChildren >
173- <div > 1 -> React . int </div >
174- <div > 2 -> React . int </div >
175- <div > 3 -> React . int </div >
171+ {React . array([|
172+ <div > 1 -> React . int </div >,
173+ <div > 2 -> React . int </div >,
174+ <div > 3 -> React . int </div >,
175+ |] )}
176176 </DummyComponentThatMapsChildren >,
177177 );
178178
@@ -461,7 +461,7 @@ describe("React", () => {
461461
462462 let container =
463463 ReactTestingLibrary . render(
464- <Test > {Test . name: "foo" } {name: "bar" } </Test >,
464+ <Test > {[| { Test . name: "foo" }, {name: "bar" } |] } </Test >,
465465 );
466466
467467 let foo = getByRole("foo" , container);
@@ -470,4 +470,52 @@ describe("React", () => {
470470 let bar = getByRole("bar" , container);
471471 expect(bar-> innerHTML)-> toBe("bar" );
472472 });
473+
474+ test("Can render components with multiple children" , () => {
475+ module MyComponent = {
476+ [@ react . component ]
477+ let make = (~children) => {
478+ <section role= "container" > children </section >;
479+ };
480+ };
481+
482+ let container =
483+ ReactTestingLibrary . render(
484+ <MyComponent >
485+ <div role= "child1" > {React . string("child1" )} </div >
486+ <div role= "child2" > {React . string("child2" )} </div >
487+ </MyComponent >,
488+ );
489+
490+ let section = getByRole("container" , container);
491+ expect(section-> tagName-> Js . String . toLowerCase)-> toBe("section" );
492+
493+ let child1 = getByRole("child1" , container);
494+ expect(child1-> innerHTML)-> toBe("child1" );
495+
496+ let child2 = getByRole("child2" , container);
497+ expect(child2-> innerHTML)-> toBe("child2" );
498+ });
499+
500+ test("Can render components with a single child" , () => {
501+ module MyComponent = {
502+ [@ react . component ]
503+ let make = (~children) => {
504+ <section role= "container" > children </section >;
505+ };
506+ };
507+
508+ let container =
509+ ReactTestingLibrary . render(
510+ <MyComponent >
511+ <div role= "child" > {React . string("child" )} </div >
512+ </MyComponent >,
513+ );
514+
515+ let section = getByRole("container" , container);
516+ expect(section-> tagName-> Js . String . toLowerCase)-> toBe("section" );
517+
518+ let child = getByRole("child" , container);
519+ expect(child-> innerHTML)-> toBe("child" );
520+ });
473521});
0 commit comments