File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 11import { vi } from "vitest" ;
2- import { mockAllIsIntersecting } from "../test-utils" ;
2+ import { mockAllIsIntersecting , setupIntersectionMocking } from "../test-utils" ;
33
44vi . hoisted ( ( ) => {
55 // Clear the `vi` from global, so we can detect if this is a test env
66 // @ts -ignore
77 window . vi = undefined ;
88} ) ;
99
10+ afterEach ( ( ) => {
11+ vi . resetAllMocks ( ) ;
12+ } ) ;
13+
1014test ( "should warn if not running in test env" , ( ) => {
1115 vi . spyOn ( console , "error" ) . mockImplementation ( ( ) => { } ) ;
1216 mockAllIsIntersecting ( true ) ;
@@ -26,3 +30,10 @@ afterEach(() => {
2630 resetIntersectionMocking();
2731});` ) ;
2832} ) ;
33+
34+ test ( 'should not warn if running in test env with global "vi"' , ( ) => {
35+ vi . spyOn ( console , "error" ) . mockImplementation ( ( ) => { } ) ;
36+ setupIntersectionMocking ( vi . fn ) ;
37+ mockAllIsIntersecting ( true ) ;
38+ expect ( console . error ) . not . toHaveBeenCalled ( ) ;
39+ } ) ;
Original file line number Diff line number Diff line change @@ -34,6 +34,16 @@ function isMocking() {
3434 if ( util && typeof util . isMockFunction === "function" ) {
3535 return util . isMockFunction ( window . IntersectionObserver ) ;
3636 }
37+
38+ // No global test utility found. Check if the IntersectionObserver was manually mocked.
39+ if (
40+ typeof window !== "undefined" &&
41+ window . IntersectionObserver &&
42+ "mockClear" in window . IntersectionObserver
43+ ) {
44+ return true ;
45+ }
46+
3747 return false ;
3848}
3949
You can’t perform that action at this time.
0 commit comments