File tree Expand file tree Collapse file tree 1 file changed +4
-6
lines changed Expand file tree Collapse file tree 1 file changed +4
-6
lines changed Original file line number Diff line number Diff line change @@ -34,21 +34,20 @@ const originalIntersectionObserver =
3434 */
3535if (
3636 typeof window !== "undefined" &&
37- typeof beforeAll !== "undefined" &&
3837 typeof beforeEach !== "undefined" &&
3938 typeof afterEach !== "undefined"
4039) {
41- const initMocking = ( ) => {
40+ beforeEach ( ( ) => {
4241 // Use the exposed mock function. Currently, it supports Jest (`jest.fn`) and Vitest with globals (`vi.fn`).
4342 // @ts -ignore
4443 if ( typeof jest !== "undefined" ) setupIntersectionMocking ( jest . fn ) ;
4544 else if ( typeof vi !== "undefined" ) {
4645 setupIntersectionMocking ( vi . fn ) ;
4746 }
48- } ;
47+ // Ensure there's no observers from previous tests
48+ observers . clear ( ) ;
49+ } ) ;
4950
50- beforeAll ( initMocking ) ;
51- beforeEach ( initMocking ) ;
5251 afterEach ( resetIntersectionMocking ) ;
5352}
5453
@@ -95,7 +94,6 @@ afterEach(() => {
9594 * @param mockFn The mock function to use. Defaults to `vi.fn`.
9695 */
9796export function setupIntersectionMocking ( mockFn : typeof vi . fn ) {
98- if ( isMocking ( ) ) return ;
9997 window . IntersectionObserver = mockFn ( ( cb , options = { } ) => {
10098 const item = {
10199 callback : cb ,
You can’t perform that action at this time.
0 commit comments