File tree 1 file changed +4
-6
lines changed
1 file changed +4
-6
lines changed Original file line number Diff line number Diff line change @@ -34,21 +34,20 @@ const originalIntersectionObserver =
34
34
*/
35
35
if (
36
36
typeof window !== "undefined" &&
37
- typeof beforeAll !== "undefined" &&
38
37
typeof beforeEach !== "undefined" &&
39
38
typeof afterEach !== "undefined"
40
39
) {
41
- const initMocking = ( ) => {
40
+ beforeEach ( ( ) => {
42
41
// Use the exposed mock function. Currently, it supports Jest (`jest.fn`) and Vitest with globals (`vi.fn`).
43
42
// @ts -ignore
44
43
if ( typeof jest !== "undefined" ) setupIntersectionMocking ( jest . fn ) ;
45
44
else if ( typeof vi !== "undefined" ) {
46
45
setupIntersectionMocking ( vi . fn ) ;
47
46
}
48
- } ;
47
+ // Ensure there's no observers from previous tests
48
+ observers . clear ( ) ;
49
+ } ) ;
49
50
50
- beforeAll ( initMocking ) ;
51
- beforeEach ( initMocking ) ;
52
51
afterEach ( resetIntersectionMocking ) ;
53
52
}
54
53
@@ -95,7 +94,6 @@ afterEach(() => {
95
94
* @param mockFn The mock function to use. Defaults to `vi.fn`.
96
95
*/
97
96
export function setupIntersectionMocking ( mockFn : typeof vi . fn ) {
98
- if ( isMocking ( ) ) return ;
99
97
window . IntersectionObserver = mockFn ( ( cb , options = { } ) => {
100
98
const item = {
101
99
callback : cb ,
You can’t perform that action at this time.
0 commit comments