get rid of mockImplementation(() => promise) - causing memory leaks
Some checks failed
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Failing after 37m26s

This commit is contained in:
2025-11-27 11:00:07 -08:00
parent 1c5c50ff20
commit 807c65130a
11 changed files with 136 additions and 87 deletions

View File

@@ -1,6 +1,6 @@
// src/pages/admin/components/AdminBrandManager.test.tsx
import React from 'react';
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import { render, screen, fireEvent, waitFor, act } from '@testing-library/react';
import { describe, it, expect, vi, beforeEach } from 'vitest';
import toast from 'react-hot-toast';
import { AdminBrandManager } from './AdminBrandManager';
@@ -24,10 +24,18 @@ describe('AdminBrandManager', () => {
vi.clearAllMocks();
});
it('should render a loading state initially', () => {
mockedApiClient.fetchAllBrands.mockReturnValue(new Promise(() => {})); // Never resolves
it('should render a loading state initially', async () => {
let resolvePromise: (value: Response) => void;
const mockPromise = new Promise<Response>(resolve => {
resolvePromise = resolve;
});
mockedApiClient.fetchAllBrands.mockReturnValue(mockPromise);
render(<AdminBrandManager />);
expect(screen.getByText('Loading brands...')).toBeInTheDocument();
await act(async () => {
resolvePromise(new Response(JSON.stringify([])));
await mockPromise;
});
});
it('should render an error message if fetching brands fails', async () => {