From 9ec7c1227621d2260be0e4c94ce2605ce21f0890 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Ch=C3=A1varri?= Date: Tue, 4 Jun 2024 04:09:22 +0200 Subject: [PATCH] test: memo and renders (#825) --- test/React__test.re | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/test/React__test.re b/test/React__test.re index b96e9da61..bfa76985e 100644 --- a/test/React__test.re +++ b/test/React__test.re @@ -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; +
{Printf.sprintf("`a` is %s", a) |> React.string}
; + }; + }; + + module Memo = { + let renders = ref(0); + + [@react.component] + let make = + React.memo((~a) => { + renders := renders^ + 1; +
{Printf.sprintf("`a` is %s", a) |> React.string}
; + }); + }; + + act(() => { + ReactDOM.Client.render( + root, +
, + ) + }); + act(() => { + ReactDOM.Client.render( + root, +
, + ) + }); + act(() => { + ReactDOM.Client.render( + root, +
, + ) + }); + + expect(Normal.renders^)->toBe(3); + + expect(Memo.renders^)->toBe(2); + }); });