Skip to content

Commit d4b62fd

Browse files
committed
chore: properly ignore React.act type
1 parent 6e459f2 commit d4b62fd

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

src/test-utils.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ let isMocking = false;
1111

1212
const observers = new Map<IntersectionObserver, Item>();
1313

14-
// If we are running in a valid testing environment, we can mock the IntersectionObserver.
14+
/*
15+
** If we are running in a valid testing environment, we can automate mocking the IntersectionObserver.
16+
*/
1517
if (
1618
typeof window !== "undefined" &&
1719
typeof beforeAll !== "undefined" &&
@@ -31,6 +33,23 @@ if (
3133
});
3234
}
3335

36+
function getActFn() {
37+
if (
38+
!(
39+
typeof window !== "undefined" &&
40+
// @ts-ignore
41+
window.IS_REACT_ACT_ENVIRONMENT
42+
)
43+
) {
44+
return undefined;
45+
}
46+
47+
return typeof React.act === "function"
48+
? // @ts-ignore - Older versions of React don't have the `act` method, so TypeScript will complain about it
49+
React.act
50+
: DeprecatedReactTestUtils.act;
51+
}
52+
3453
function warnOnMissingSetup() {
3554
if (isMocking) return;
3655
console.error(
@@ -103,23 +122,6 @@ export function resetIntersectionMocking() {
103122
observers.clear();
104123
}
105124

106-
function getActFn() {
107-
if (
108-
!(
109-
typeof window !== "undefined" &&
110-
// @ts-ignore
111-
window.IS_REACT_ACT_ENVIRONMENT
112-
)
113-
) {
114-
return undefined;
115-
}
116-
117-
// @ts-ignore - Older versions of React don't have the `act` method, so TypeScript will complain about it
118-
return typeof React.act === "function"
119-
? React.act
120-
: DeprecatedReactTestUtils.act;
121-
}
122-
123125
function triggerIntersection(
124126
elements: Element[],
125127
trigger: boolean | number,

0 commit comments

Comments
 (0)