Skip to content

Commit

Permalink
fix: test-utils - execute mockClear method only when it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
karpiuMG committed Jun 4, 2024
1 parent dceba7f commit 712ae37
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,13 @@ export function setupIntersectionMocking(mockFn: typeof jest.fn) {
* Reset the IntersectionObserver mock to its initial state, and clear all the elements being observed.
*/
export function resetIntersectionMocking() {
// @ts-ignore
if (global.IntersectionObserver) global.IntersectionObserver.mockClear();
if (
global.IntersectionObserver &&
"mockClear" in global.IntersectionObserver &&
typeof global.IntersectionObserver.mockClear === "function"
) {
global.IntersectionObserver.mockClear();
}
observers.clear();
}

Expand Down

0 comments on commit 712ae37

Please sign in to comment.