From 4c25f65fc262923379487a1458782c66e2432771 Mon Sep 17 00:00:00 2001 From: Brant Barger Date: Sun, 7 Apr 2024 21:13:25 +0000 Subject: [PATCH] fix: test utils, only use act when in an act environment --- src/test-utils.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/test-utils.ts b/src/test-utils.ts index 3acf9a20..c6caae44 100644 --- a/src/test-utils.ts +++ b/src/test-utils.ts @@ -93,6 +93,10 @@ export function resetIntersectionMocking() { observers.clear(); } +function getIsReactActEnvironment() { + return Boolean(global.IS_REACT_ACT_ENVIRONMENT); +} + function triggerIntersection( elements: Element[], trigger: boolean | number, @@ -148,7 +152,8 @@ function triggerIntersection( } // Trigger the IntersectionObserver callback with all the entries - if (act) act(() => item.callback(entries, observer)); + if (act && getIsReactActEnvironment()) + act(() => item.callback(entries, observer)); else item.callback(entries, observer); } /**