Skip to content

Commit

Permalink
fix: test utils, only use act when in an act environment
Browse files Browse the repository at this point in the history
  • Loading branch information
brantphoto committed Apr 7, 2024
1 parent e1391be commit 4c25f65
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
/**
Expand Down

0 comments on commit 4c25f65

Please sign in to comment.