Skip to content

Commit

Permalink
test: memo and renders (#825)
Browse files Browse the repository at this point in the history
  • Loading branch information
jchavarri authored Jun 4, 2024
1 parent 470a284 commit 9ec7c12
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions test/React__test.re
Original file line number Diff line number Diff line change
Expand Up @@ -359,4 +359,54 @@ describe("React", () => {
/* We catch the exception here to not populate the error to the toplevel */
()
};

test(
"Memo and normal components rendering with equal and different props", () => {
let container = getContainer(container);
let root = ReactDOM.Client.createRoot(container);

module Normal = {
let renders = ref(0);

[@react.component]
let make = (~a) => {
renders := renders^ + 1;
<div> {Printf.sprintf("`a` is %s", a) |> React.string} </div>;
};
};

module Memo = {
let renders = ref(0);

[@react.component]
let make =
React.memo((~a) => {
renders := renders^ + 1;
<div> {Printf.sprintf("`a` is %s", a) |> React.string} </div>;
});
};

act(() => {
ReactDOM.Client.render(
root,
<div> <Normal a="a" /> <Memo a="a" /> </div>,
)
});
act(() => {
ReactDOM.Client.render(
root,
<div> <Normal a="a" /> <Memo a="a" /> </div>,
)
});
act(() => {
ReactDOM.Client.render(
root,
<div> <Normal a="b" /> <Memo a="b" /> </div>,
)
});

expect(Normal.renders^)->toBe(3);

expect(Memo.renders^)->toBe(2);
});
});

0 comments on commit 9ec7c12

Please sign in to comment.