Skip to content

Commit

Permalink
Add test for props as a children
Browse files Browse the repository at this point in the history
  • Loading branch information
davesnx committed Dec 13, 2024
1 parent 44f532a commit 6457a13
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions packages/reactDom/test/test_RSC_model.ml
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,58 @@ let mixed_server_and_client () =
"0:\"$1\"\n";
]

let client_with_server_children () =
let server_child () = React.createElement "div" [] [ React.string "Server Component Inside Client" ] in
let app () =
React.Upper_case_component
(fun () ->
React.List
[|
React.createElement "div" [] [ React.string "Server Content" ];
React.Client_component
{
props = [ ("children", React.Element (React.Upper_case_component server_child)) ];
client = React.string "Client with Server Children";
import_module = "./client-with-server-children.js";
import_name = "ClientWithServerChildren";
};
|])
in
let%lwt stream = ReactServerDOM.render_to_model (app ()) in
assert_stream stream
[
"2:I[\"./client-with-server-children.js\",[],\"ClientWithServerChildren\"]\n";
"3:[\"$\",\"div\",null,{\"children\":\"Server Component Inside Client\"}]\n";
"1:[[\"$\",\"div\",null,{\"children\":\"Server Content\"}],[\"$\",\"$2\",null,{\"children\":\"$3\"}]]\n";
"0:\"$1\"\n";
]

let client_with_server_children () =
let server_child () = React.createElement "div" [] [ React.string "Server Component Inside Client" ] in
let app () =
React.Upper_case_component
(fun () ->
React.List
[|
React.createElement "div" [] [ React.string "Server Content" ];
React.Client_component
{
props = [ ("children", React.Element (React.Upper_case_component server_child)) ];
client = React.string "Client with Server Children";
import_module = "./client-with-server-children.js";
import_name = "ClientWithServerChildren";
};
|])
in
let%lwt stream = ReactServerDOM.render_to_model (app ()) in
assert_stream stream
[
"2:I[\"./client-with-server-children.js\",[],\"ClientWithServerChildren\"]\n";
"3:[\"$\",\"div\",null,{\"children\":\"Server Component Inside Client\"}]\n";
"1:[[\"$\",\"div\",null,{\"children\":\"Server Content\"}],[\"$\",\"$2\",null,{\"children\":\"$3\"}]]\n";
"0:\"$1\"\n";
]

let tests =
[
test "null_element" null_element;
Expand All @@ -407,4 +459,5 @@ let tests =
test "client_without_props" client_without_props;
test "client_with_element_props" client_with_element_props;
test "client_with_promise_props" client_with_promise_props;
test "client_with_server_children" client_with_server_children;
]

0 comments on commit 6457a13

Please sign in to comment.