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/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 () => {
|
||||
|
||||
Reference in New Issue
Block a user