get rid of mockImplementation(() => promise) - causing memory leaks
Some checks failed
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Failing after 37m26s
Some checks failed
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Failing after 37m26s
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// src/components/PriceHistoryChart.test.tsx
|
||||
import React from 'react';
|
||||
import { render, screen, waitFor } from '@testing-library/react';
|
||||
import { render, screen, waitFor, act } from '@testing-library/react';
|
||||
import { describe, it, expect, vi, beforeEach, type Mock } from 'vitest';
|
||||
import { PriceHistoryChart } from './PriceHistoryChart';
|
||||
import * as apiClient from '../../services/apiClient';
|
||||
@@ -56,11 +56,19 @@ describe('PriceHistoryChart', () => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should render a loading spinner while fetching data', () => {
|
||||
(apiClient.fetchHistoricalPriceData as Mock).mockReturnValue(new Promise(() => {}));
|
||||
it('should render a loading spinner while fetching data', async () => {
|
||||
let resolvePromise: (value: Response) => void;
|
||||
const mockPromise = new Promise<Response>(resolve => {
|
||||
resolvePromise = resolve;
|
||||
});
|
||||
(apiClient.fetchHistoricalPriceData as Mock).mockReturnValue(mockPromise);
|
||||
render(<PriceHistoryChart watchedItems={mockWatchedItems} />);
|
||||
expect(screen.getByText(/loading price history/i)).toBeInTheDocument();
|
||||
expect(screen.getByRole('status')).toBeInTheDocument(); // LoadingSpinner
|
||||
await act(async () => {
|
||||
resolvePromise(new Response(JSON.stringify([])));
|
||||
await mockPromise;
|
||||
});
|
||||
});
|
||||
|
||||
it('should render an error message if fetching fails', async () => {
|
||||
|
||||
Reference in New Issue
Block a user