Fix IntersectionObserver mock for updated lib.dom.d.ts
This commit is contained in:
commit
b6a4c70a7a
15 files changed
+779
-2239
No files matched your search
+53
-9
@@ -1,15 +1,59 @@
|
||||
import '@testing-library/jest-dom/vitest';
|
||||
import { afterAll, afterEach, beforeAll } from 'vitest';
|
||||
import { server } from './msw/server';
|
||||
import { cleanup, configure } from '@testing-library/react';
|
||||
import { afterEach, vi } from 'vitest';
|
||||
import { resetTestNavigation } from './navigation';
|
||||
|
||||
beforeAll(() => {
|
||||
server.listen({ onUnhandledRequest: 'error' });
|
||||
configure({ testIdAttribute: 'data-test' });
|
||||
|
||||
Object.defineProperty(window, 'matchMedia', {
|
||||
writable: true,
|
||||
value: vi.fn().mockImplementation((query: string) => ({
|
||||
matches: false,
|
||||
media: query,
|
||||
onchange: null,
|
||||
addEventListener: vi.fn(),
|
||||
removeEventListener: vi.fn(),
|
||||
addListener: vi.fn(),
|
||||
removeListener: vi.fn(),
|
||||
dispatchEvent: vi.fn(),
|
||||
})),
|
||||
});
|
||||
|
||||
Object.defineProperty(navigator, 'clipboard', {
|
||||
configurable: true,
|
||||
value: {
|
||||
readText: vi.fn(),
|
||||
writeText: vi.fn(),
|
||||
},
|
||||
});
|
||||
|
||||
window.scrollTo = vi.fn();
|
||||
|
||||
class ResizeObserver {
|
||||
observe() {}
|
||||
unobserve() {}
|
||||
disconnect() {}
|
||||
}
|
||||
|
||||
class IntersectionObserver {
|
||||
readonly root = null;
|
||||
readonly rootMargin = '';
|
||||
readonly scrollMargin = '';
|
||||
readonly thresholds = [];
|
||||
|
||||
observe() {}
|
||||
unobserve() {}
|
||||
disconnect() {}
|
||||
takeRecords() {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
window.ResizeObserver = ResizeObserver;
|
||||
window.IntersectionObserver = IntersectionObserver;
|
||||
|
||||
afterEach(() => {
|
||||
server.resetHandlers();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
server.close();
|
||||
cleanup();
|
||||
resetTestNavigation();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
Reference in new issue
Block a user