diff options
Diffstat (limited to 'frontend/src/components/FeedItems.test.tsx')
| -rw-r--r-- | frontend/src/components/FeedItems.test.tsx | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/frontend/src/components/FeedItems.test.tsx b/frontend/src/components/FeedItems.test.tsx index cf1e708..25ade58 100644 --- a/frontend/src/components/FeedItems.test.tsx +++ b/frontend/src/components/FeedItems.test.tsx @@ -17,11 +17,12 @@ describe('FeedItems Component', () => { unobserve = vi.fn(); disconnect = vi.fn(); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any window.IntersectionObserver = MockIntersectionObserver as any; }); it('renders loading state', () => { - (global.fetch as any).mockImplementation(() => new Promise(() => { })); + vi.mocked(global.fetch).mockImplementation(() => new Promise(() => { })); render( <MemoryRouter initialEntries={['/feed/1']}> <Routes> @@ -50,10 +51,10 @@ describe('FeedItems Component', () => { }, ]; - (global.fetch as any).mockResolvedValueOnce({ + vi.mocked(global.fetch).mockResolvedValueOnce({ ok: true, json: async () => mockItems, - }); + } as Response); render( <MemoryRouter initialEntries={['/feed/1']}> @@ -79,10 +80,10 @@ describe('FeedItems Component', () => { { _id: 102, title: 'Item 2', url: 'u2', read: true, starred: false }, ]; - (global.fetch as any).mockResolvedValue({ + vi.mocked(global.fetch).mockResolvedValue({ ok: true, json: async () => mockItems, - }); + } as Response); render( <MemoryRouter> @@ -134,10 +135,10 @@ describe('FeedItems Component', () => { it('marks items as read when scrolled past', async () => { const mockItems = [{ _id: 101, title: 'Item 1', url: 'u1', read: false, starred: false }]; - (global.fetch as any).mockResolvedValue({ + vi.mocked(global.fetch).mockResolvedValue({ ok: true, json: async () => mockItems, - }); + } as Response); // Capture both callbacks const observerCallbacks: IntersectionObserverCallback[] = []; @@ -151,8 +152,10 @@ describe('FeedItems Component', () => { unobserve = vi.fn(); disconnect = vi.fn(); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any window.IntersectionObserver = MockIntersectionObserver as any; + render( <MemoryRouter> <FeedItems /> @@ -201,9 +204,9 @@ describe('FeedItems Component', () => { const initialItems = [{ _id: 101, title: 'Item 1', url: 'u1', read: true, starred: false }]; const moreItems = [{ _id: 100, title: 'Item 0', url: 'u0', read: true, starred: false }]; - (global.fetch as any) - .mockResolvedValueOnce({ ok: true, json: async () => initialItems }) - .mockResolvedValueOnce({ ok: true, json: async () => moreItems }); + vi.mocked(global.fetch) + .mockResolvedValueOnce({ ok: true, json: async () => initialItems } as Response) + .mockResolvedValueOnce({ ok: true, json: async () => moreItems } as Response); const observerCallbacks: IntersectionObserverCallback[] = []; class MockIntersectionObserver { @@ -214,8 +217,10 @@ describe('FeedItems Component', () => { unobserve = vi.fn(); disconnect = vi.fn(); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any window.IntersectionObserver = MockIntersectionObserver as any; + render( <MemoryRouter> <FeedItems /> @@ -267,9 +272,9 @@ describe('FeedItems Component', () => { { _id: 100, title: 'Item 0', url: 'u0', read: true, starred: false }, ]; - (global.fetch as any) - .mockResolvedValueOnce({ ok: true, json: async () => initialItems }) - .mockResolvedValueOnce({ ok: true, json: async () => moreItems }); + vi.mocked(global.fetch) + .mockResolvedValueOnce({ ok: true, json: async () => initialItems } as Response) + .mockResolvedValueOnce({ ok: true, json: async () => moreItems } as Response); render( <MemoryRouter> |
